Calculating the darker or lighter version of a color
-
Hi, in my text based game i need to calculate the darker and lighter version of a color stored into a variable, so how the colour representation works? and how can i do this calculation?
-
For the actual calculation i just need to get the RGB values for the color and increase them using the same constant value, but the problem is getting those values, settimg them is quite straight forward as i saw in the documentation
-
Colors are just stored as vector objects. So it's fairly easy to get the values simply by using r, g, b, and a.
myColor = white red = myColor.r
The individual r/g/b/a colors are stored as values between 0 and 1, so to get the actual RGB value, you'd need to multiply by 255. For example,
white.r
is1.000000
. So, multiplied by 255 would be255
, the expected value for white. -
thank you very mutch, it will help with parts in which you can sneak under things.
-
I actually just wrote a function that turns a HSL (hue, saturation, lightness) to RGB
function HSL2RGB(h, s, l, a) float v float r = l float g = l float b = l if l <= 0.5 then v = l * (1.0 + s) else v = l + s - (l * s) endif if v > 0 then float m float sv int sextant float frct float vsf float mid1 float mid2 m = l + l - v sv = (v - m) / v h = h * 6.0 sextant = floor(h) frct = h - sextant vsf = v * sv * frct mid1 = m + vsf mid2 = v - vsf if sextant == 0 then r = v g = mid1 b = m else if sextant == 1 then r = mid2 g = v b = m else if sextant == 2 then r = m g = v b = mid1 else if sextant == 3 then r = m g = mid2 b = v else if sextant == 4 then r = mid1 g = m b = v else if sextant == 5 then r = v g = m b = mid2 else r = v g = m b = mid2 endif endif endif endif endif endif endif print("R: " + r + " G: " + g + " B: " + b + " A: " + a + " V: " + v + " " + " H: " + h + "\n" ) vector color = {r, g, b, a} return color
so if you have something that is red it would look like HSL2RGB(0, 1, 0.5, 1)
The l parameter is used for how light/dark that color is
You can check those values here: http://hslpicker.com/#f00 -
This post is deleted! -
@ITzTravelInTime does that work for you?
-
@Jaywalker I just used a simpler algorith i found online, i just needed the RGB components
-
Okay good :)