-
Senior Member
colours and shades
hello,
i have 20 mc's, when i pick a colour from my colour picker component i want the 20 mc's to show the various shades of the colour selected (from dark to light).
i have tried using setTransform() but all i get is a white - black "shade spectrum"
how would i go about getting the various shades of a colour?
also, how can i extract the seperate R, G and B values from a RGB value?
many thanks,
zlatan
-
I Peiced this code together while building a smaller ComboBox Component for an online app. You can experiment with it as it does exactly what you describe. I found it to be very useful while setting color themes and creating several shades and borders from one RGB value:
Code:
var rgb = 0x53AC82
//extacts the red channel
var red = (rgb & 16711680) >> 16;
//extacts the green channel
var green = (rgb & 65280) >> 8;
//extacts the blue channel
var blue = rgb & 255;
//Adjusts color monochrome +40% upto 255 Max
//Positive adjustments lighten
//Negative adjustments darken
red = (red * 1.4) < 255 ? red * 1.4 : 255;
green = (green * 1.4) < 255 ? green * 1.4 : 255;
blue = (blue * 1.4) < 255 ? blue * 1.4 : 255;
//Convert back to Hex
var c = red << 16 | green << 8 | blue;
trace(c)
-
Senior Member
thanks, but you code does not work with the "primary colours" such as 0x00ff00 and 0xff0000, also i dont see a way of changing the difference between the 2 shades.
please correct me if i am mistaken,
thanks again,
zlatan
-
Correct, look at the math of the code. green and blue = 0 when extracting from 0xff0000 and 0*1.4 = 0, when it needs to be >0 to lighten.
Experiment with this code and you can come up with something that suites you needs.
-
you could do this...
Code:
red = (red * 1.4) < 255 ? red * 1.4 : 255;
red = red == 0 ? 255 * .4 : red;
green = (green * 1.4) < 255 ? green * 1.4 : 255;
green = green == 0 ? 255 * .4 : green;
blue = (blue * 1.4) < 255 ? blue * 1.4 : 255;
blue = blue == 0 ? 255 * .4 : blue;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|