Hi everyone,
Im having some math problems with a BitmapData and setPixel().
Im using a for loop to calculate the different color values that should be
assigned to a BitmapData, creating a gradient with a specific shape. Problem
is that I cant get the right combination of color and shape of the
gradient.
In the sample code (which you can copy and paste and it will work straight
away) I set two examples of the var p.
The first option has the shape that I want. The issue is that the colors
that are in the top and bottom center (very dark green and very light green)
should be in the corners of their respective top and bottom.
The second option has somewhat the color distribution that I want, but I
doesnt have the shape that I need. Here the curvature starts in the
corners, but should be as in the first option.
I know it is a problematic question, but I would love to see your replies,
as I have tried to solve this little problem for quite some time now.
Claudia Barnal
// CODE
var stageW:Number = 255;
var stageH:Number = 255;
var hStageMiddle:Number = Math.round((stageW / 2) + 1);
var bd:flash.display.BitmapData = new flash.display.BitmapData(stageW,
stageH);
for (var x:Number = 0; x < hStageMiddle; x++)
{
/*
* OPTION1 RIGHT SHAPE, WRONG COLOR DISTRIBUTION
* CURVE STARTS FROM TOP AND BOTTOM CENTER
*/
var p:Number = Math.pow(1 - (x / hStageMiddle), 2);
/*
* OPTION2 WRONG SHAPE, RIGHT COLOR DISTRIBUTION
* CURVE STARTS FROM THE CORNERS, WHICH IS WRONG
*/
//var p:Number = Math.pow(2, 1 - (x / hStageMiddle));
for (var y:Number = 0; y < stageH; y++)
{
var val1:Number = ((255 * y) / stageH);
var val2:Number = ((val1 * (1 - p)) + (128 * p));
var col:Number = (((val2 << 8) | 0) | 0);
bd.setPixel(x, y, col);
bd.setPixel(stageW - x, y, col);
}
}
createEmptyMovieClip("bmp", 1);
bmp.attachBitmap(bd, 2);
// CODE END
_________________________________________________________________
The new MSN Search Toolbar now includes Desktop search!
http://toolbar.msn.co.uk/
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders