Couple of weeks back I was going through the "BitmapData" class that is in the flash display package. My idea was to implement different types of brush (brush stroke) like in the photoshope into a small drawing application.Finally the whole thing became very simple.
The idea is when the user drag the mouse over the canvas we have to draw a pattern, a normal stroke will be a circle or a rectangle but here we need some custom strokes.
First we will identify a pattern which would be a combination of single pixel squares arranged to get the specific pattern.To get this pattern at run time we write a loop which uses the 'fillRect' functionality to create the pattern.
Each brush strokes would be a class on its draw function implements the fillRect according to the pattern.
dummy code will look like this
public function mouseMove(event:Event):void {
if(_drawMe){
brushStroke(_color); }
}
private function brushStroke(_color):void {
var fiber_lng:Number =30;
for(var i:int=0;i<=fiber_lng;i++){
bitmap.fillRect(new Rectangle(mouseX+Math.round(Math.random()*10), mouseY+Math.round(Math.random()*10),_pixelWidth, _pixelHight), _color);
}
}
Since we are only changing the color values of a canvas, this approach has proved very smooth and fast, and the main thing that has to taken care of is not overdoing the loops to create complex strokes.
Hope this will help in some of your application
Thursday, March 13, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment