DarkByte Posted January 1, 2017 Share Posted January 1, 2017 How it's possible to make the respect color like in the image. For example if respect is 0 to be green, if it's decreasing to get to red and if increasing to go to blu and so..like in this spectrum below Link to comment
Simple0x47 Posted January 1, 2017 Share Posted January 1, 2017 You have to use statments and interpolateBetween. Link to comment
DarkByte Posted January 1, 2017 Author Share Posted January 1, 2017 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
Simple0x47 Posted January 1, 2017 Share Posted January 1, 2017 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
myonlake Posted January 2, 2017 Share Posted January 2, 2017 -- 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. 1 Link to comment
DarkByte Posted January 3, 2017 Author Share Posted January 3, 2017 but how to increase it like a gradient? to change the color step by step hope you understood me Link to comment
myonlake Posted January 3, 2017 Share Posted January 3, 2017 10 hours ago, DarkByte said: but how to increase it like a gradient? to change the color step by step hope you understood me Use interpolateBetween, you could try something yourself for a change. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now