Pointillism in AS3 with BitmapData
The BitmapData.getPixel method is a pretty interesting method. In previous posts I've experimented, using the number it returns, to scale, rotate, move, and in my last post, create a halftone pattern.
The getPixel method is defined by Adobe as:
Returns an integer that represents an RGB pixel value from a BitmapData object at a specific point (x, y). The getPixel() method returns an unmultiplied pixel value. No alpha information is returned.
Where in the last post I used the getPixel number to scale the sprites within a grid, creating a halftone pattern, here I simply use the number as the color of each sprite, resulting in a pointillism effect.
The code is as follows:
// set up Properties var imgW:int = 295; var imgH:int = 250; var dotSize:int = 5; var gridW:Number = Math.ceil( imgW / dotSize ); var gridH:Number = Math.ceil( imgH / dotSize ); var contain:Sprite = new Sprite(); var myBD:BitmapData = new BitmapData(imgW, imgH); function init():void { myBD.draw( Photo ); addChild( contain ); contain.x = 295; addNodes(); } function addNodes() { var colCNT:int = 0; var rowCNT:int = 0; // build grid for (var i:int = 0; i < gridW * gridH; i++) { // add sprite var myDot:Sprite = new Sprite(); // place in grid myDot.x = colCNT * dotSize; myDot.y = rowCNT * dotSize; // get color var pixelColor:int = myBD.getPixel( myDot.x, myDot.y); // build dots myDot.graphics.lineStyle( dotSize, pixelColor, 1); myDot.graphics.moveTo(0, 0); myDot.graphics.lineTo(1, 1); // add contain.addChild( myDot ); // update if ( colCNT < gridW - 1 ) { colCNT ++; } else { rowCNT ++; colCNT = 0; } } } init();
No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URI
Leave a comment