Reputation: 11
Hai, i am a newbie to actionscript.
i am trying to make a brush tool in actionscript 3, where kids can paint colors inside a circle using the brush. i have achieved this using linestyle. Now i want the brush to snap the color when the kid is about to complete(say when they are 95% to complete the painting). How do i know how much the kid has painted on the circle?
Thanks
Upvotes: 1
Views: 438
Reputation: 9897
How do i know how much the kid has painted on the circle?
You can:
How to count pixels:
function countPixels(shape:DisplayObject):int
{
var bd:BitmapData = new BitmapData(shape.width, shape.height);
bd.draw(shape);
//here you get sequence of ARGB-packed colors in vector
var pixels:Vector.<uint> = bd.getVector(bd.rect);
//AFAIK, fastest method to traverse vector is 'for' loop
var pixel:uint;
var filledCount:int = 0;
for (var i:int = pixels.length - 1; i >= 0; i--)
{
pixel = pixels[i];
//pixel is 32-bit ARGB color value, test upper 8 bits (alpha):
if ((pixel >> 24) > 0) filledCount++;
}
return filledCount;
}
Run this on filled shape to get total pixel count to compare with.
After pixelCount reaches 95%, you can clear kid's drawing and show filled shape.
Upvotes: 1