Does anyone know how to create two new colours (highlight and shadow) based on one colour in ActionScript 3? So, if I have red (0xFF0000), I will get a light red and dark red too?
I have no idea. Thanks!
Does anyone know how to create two new colours (highlight and shadow) based on one colour in ActionScript 3? So, if I have red (0xFF0000), I will get a light red and dark red too?
I have no idea. Thanks!
To get Highlight (lightness) you increase each R, G and B equally by same amount (with maximum at
255
or0xFF
). In your case Red is already at its maximum so increase both Green and Blue by same amount (eg do a+= 128
on each of those channels).To get Shadow (darkness) you decrease each R, G and B equally by same amount (with minimum at
0
or0x00
). In your case both Green and Blue are already at their minimum so just decrease only Red by x amount (eg do a-= 128
on Red channel).In short:
Input =
0xFF0000
... then Highlight =0xFF8080
and Shadow =0x800000
.Update:
A good point was made in the comments about highlight/shadow cases of other colours (or hues). If we agree that "lighter" means adding more white and "darker" means adding more black then maybe a linear interpolation might help you (basically make a gradient of input colour fading to black or to white and choose your preferred darker/lighter colour along those A-to-B paths...
PS: By interpolating, you'll have the flexibility of blending to different hues and shades of lightness/darkness. Maybe blend from a bright red towards a darker reddish-purple (instead of just black) for "sweeter" shade colours, and your greens could have yellow highlights (instead of just white). Blue is up to you.
example usage:
Example function:
(note:
(temp_int >> 0)
is used here as a quickMath.Floor
for any fractioned results)