We can create random shades of green by picking low random values for red and blue and more of green. The code is shown below:
var light,medium,dark:int; //3 shades of the same color
colorPicker.addEventListener(Event.CHANGE,pickColor);
function pickColor(e:Event):void {
var colorT:ColorTransform = new ColorTransform();
setShades();
colorT.color = light;
flower.lightArea.transform.colorTransform = colorT; //change the color of the box
colorT.color = medium;
flower.colorArea.transform.colorTransform = colorT; //change the color of the box
colorT.color = dark;
flower.darkArea.transform.colorTransform = colorT; //change the color of the box
colorLeaf();
} //changeColor
function colorLeaf(): void {
var colorT:ColorTransform = new ColorTransform();
var red:int=Math.random()*150; //low red and blue values
var blue:int=Math.random()*150; //create darker colors
var green:int=200; //leaf will be a dark shade of green
colorT.color=(red*256*256)+(green*256)+blue; //RGB value
flower.leaf.transform.colorTransform = colorT; //change the color of the leaf
}
function setShades(): void {
medium=colorPicker.selectedColor;
var color:int=colorPicker.selectedColor;
var red,green,blue:int;
blue=color%256;
color=color/256;
green=color%256;
red=color/256;
var darkRed:int=red*0.6;
var darkGreen:int=green*0.6;
var darkBlue:int=blue*0.6;
dark=(darkRed*256*256)+(darkGreen*256)+darkBlue; //RGB value
//notice the difference in setting ltRed,ltGreen and ltBlue. The result is the same
var ltRed:int=red*1.5;
if(ltRed>255) ltRed=255;
var ltGreen:int=green*1.5;
ltGreen=Math.min(ltGreen,255);
var ltBlue:int=Math.min(blue*1.5,255);
light=(ltRed*256*256)+(ltGreen*256)+ltBlue; //RGB value
} //randomColor
We can create dark colors by generating lower values and pastels by keeping the values high. (But not higher than 255!)