BitmapData.floodFill()

Actionscript:
  1. var canvas:BitmapData = new BitmapData(400,400,false, 0xCC0000);
  2. addChild(new Bitmap(canvas));
  3.  
  4. var s:Shape = new Shape();
  5. s.graphics.beginFill(0x00CCCC);
  6. s.graphics.moveTo(Math.random()*400,Math.random()*400);
  7. for(var i:int = 0; i<10; i++){
  8.     s.graphics.lineTo(Math.random()*400,Math.random()*400);
  9. }
  10. canvas.draw(s);
  11.  
  12. stage.addEventListener(MouseEvent.CLICK, onDown);
  13. function onDown(evt:MouseEvent):void {
  14.     canvas.floodFill(mouseX, mouseY, 0x000000);
  15. }

floodFill() is basically the paint bucket (fill) tool in any bitmap drawing program. The above example draws an arbitrary blue polygon to a red background. Click anywhere on the resulting image to see floodFill() in action.

floodFill() takes 3 arguments... x, y and color.

This entry was posted in BitmapData, pixel manipulation and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*