Jump to content

Respect


DarkByte

Recommended Posts

Found this, but how to manage it an get it to a color?
 

local function wavelengthToRGBA(length) 
    local r, g, b, factor 
    if (length >= 380 and length < 440) then 
        r, g, b = -(length - 440)/(440 - 380), 0, 1 
    elseif (length < 489) then 
        r, g, b = 0, (length - 440)/(490 - 440), 1 
    elseif (length < 510) then 
        r, g, b = 0, 1, -(length - 510)/(510 - 490) 
    elseif (length < 580) then 
        r, g, b = (length - 510)/(580 - 510), 1, 0 
    elseif (length < 645) then 
        r, g, b = 1, -(length - 645)/(645 - 580), 0 
    elseif (length < 780) then 
        r, g, b = 1, 0, 0 
    else 
        r, g, b = 0, 0, 0 
    end 
    if (length >= 380 and length < 420) then 
        factor = 0.3 + 0.7*(length - 380)/(420 - 380) 
    elseif (length < 701) then 
        factor = 1 
    elseif (length < 780) then 
        factor = 0.3 + 0.7*(780 - length)/(780 - 700) 
    else 
        factor = 0 
    end 
    return r*255, g*255, b*255, factor*255 
end 

 

Link to comment
function getColor( length )
  local rel = length / maxLength -- Define your own maxLength for having a decimal value
  local r, g, b
  if ( rel > 0.5 ) then
    local p = ( rel * 0.75 ) / 0.5
    r, g, b = interpolateBetween( 0, 255, 0, 0, 0, 255, p, "Linear" )
  else
    local p = ( rel * 0.25 ) / 0.5
    r, g, b = interpolateBetween( 255, 0, 0, 0, 255, 0, p, "Linear" )
  end
  return r, g, b
end

 

Link to comment
-- Let's define some respect levels
local colors = {
	[ -3 ] = 420, -- Purple
	[ -2 ] = 435, -- Blue
	[ -1 ] = 480, -- Teal
	[  0 ] = 510, -- Green
	[  1 ] = 580, -- Yellow
	[  2 ] = 605, -- Orange
	[  3 ] = 670  -- Red
}

-- Let's make a function that returns us the color
local function getRespectColor( respect )
	local function wavelengthToRGBA( length, alpha )
		local r, g, b, factor

		if ( length >= 380 ) and ( length < 440 ) then
			r, g, b = -( length - 440 ) / ( 440 - 380 ), 0, 1
		elseif ( length < 489 ) then
			r, g, b = 0, ( length - 440 ) / ( 490 - 440 ), 1
		elseif ( length < 510 ) then
			r, g, b = 0, 1, -( length - 510 ) / ( 510 - 490 )
		elseif ( length < 580 ) then
			r, g, b = ( length - 510 ) / ( 580 - 510 ), 1, 0
		elseif ( length < 645 ) then
			r, g, b = 1, -( length - 645 ) / ( 645 - 580 ), 0
		elseif ( length < 780 ) then
			r, g, b = 1, 0, 0
		else
			r, g, b = 0, 0, 0
		end

		if ( alpha ) then
			if ( length >= 380 ) and ( length < 420 ) then
				factor = 0.3 + 0.7 * ( length - 380 ) / ( 420 - 380 )
			elseif ( length < 701 ) then
				factor = 1
			elseif ( length < 780 ) then
				factor = 0.3 + 0.7 * ( 780 - length ) / ( 780 - 700 )
			else
				factor = 0
			end
		else
			factor = 1
		end

		return r * 255, g * 255, b * 255, factor * 255 
	end

	return tocolor( wavelengthToRGBA( colors[ math.floor( respect ) ] or 510 ) )
end

-- Our current respect level
local respect = -3

-- Let's render to see the demo
addEventHandler( 'onClientRender', root,
	function( )
		-- Rectangle with fill color
		dxDrawRectangle( 500, 500, 100, 100, getRespectColor( respect ) )
		
		-- We draw the respect level
		dxDrawText( math.floor( respect ), 550, 550, 570, 570, tocolor( 0, 0, 0, 255 ) )

		-- Increase it over time
		respect = respect + 0.025

		-- If we're done, let's return to level -3
		if ( respect >= 4 ) then
			respect = -3
		end
	end
)

Well, here you go, perhaps this does something of that sort.

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...