By Zevan | December 25, 2008
Actionscript:
-
var canvas:BitmapData=new BitmapData(400,400,true,0x000000);
-
var eraser:BitmapData=new BitmapData(400,400,true,0x00000000);
-
addChild(new Bitmap(canvas));
-
var redOval:Shape = new Shape();
-
with(redOval.graphics) lineStyle(0,0), beginFill(0xFF0000), drawEllipse(0,0,10,50);
-
-
// draw a background to emphasize transparency
-
createBackground();
-
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
-
function onLoop(evt:Event):void {
-
// clear canvas so that it is completely transparent
-
canvas.copyPixels(eraser, eraser.rect, new Point(0,0), eraser);
-
redOval.x = mouseX;
-
redOval.y = mouseY;
-
redOval.rotation += 10
-
// transform.matrix contains all transformation information for
-
// the redOval including scaleX, scaleY, x, y, rotation etc...
-
canvas.draw(redOval, redOval.transform.matrix);
-
}
-
-
function createBackground():void {
-
for (var i:int = 0; i<100; i++){
-
with(graphics) lineStyle(0,0x000000), lineTo(Math.random()*400, Math.random()*400);
-
}
-
}
This example builds on yesterdays snippet. Instead of just allowing the red oval to be continuously drawn to the canvas BitmapData... in this example the canvas BitmapData is erased again and again before the red oval is drawn to it. To erase it with a flat color you might use BitmapData.fillRect() but if you want to erase it so that it is completely transparent you need to use BitmapData.copyPixels():
Actionscript:
-
canvas.copyPixels(eraser, eraser.rect, new Point(0,0), eraser);
The eraser BitmapData is a completely transparent BitmapData object. The key here is the fourth argument.... "alphaBitmapData".This is what causes the canvas BitmapData to become completely transparent again at the beginning of each enterFrame.
This argument is separate from the first argument (sourceBitmapData) for added flexibility.
By Zevan | December 24, 2008
Actionscript:
-
var canvas:BitmapData=new BitmapData(400,400,true,0xFFCCCCCC);
-
addChild(new Bitmap(canvas));
-
-
var redOval:Shape = new Shape();
-
with(redOval.graphics) lineStyle(0,0), beginFill(0xFF0000), drawEllipse(0,0,10,50);
-
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
-
redOval.x = mouseX;
-
redOval.y = mouseY;
-
redOval.rotation += 10
-
// transform.matrix contains all transformation information for
-
// the redOval including scaleX, scaleY, x, y, rotation etc...
-
canvas.draw(redOval, redOval.transform.matrix);
-
}
A very easy way to create a BitmapData brush.
Posted in BitmapData | Also tagged actionscript |
By Zevan | December 23, 2008
CLICK HERE FOR TODAY'S SNIPPET
In a recent kirupa thread, senocular posted an very useful snippet to aid in the creation of a two sided 3D MovieClip. The thread also contains an in depth description of polygon winding.
Description of Polygon Winding
I created a navigation demo using this technique.
Here is the source for the above demo
UPDATE
Justin Windle of soulwire has written a nice class called PaperSprite that uses this technique. The class is worth checking out - it's nicely designed... read more about it here.
By Zevan | December 22, 2008
Actionscript:
-
var colors:Array = [0xFF0000, 0x666699, 0x223322, 0xCCCCDD, 0xFFEEFF];
-
var alphas:Array = [0, 1, 1, 1, 1];
-
var ratios:Array = [0, 50, 100, 200, 255]
-
var filter:GradientGlowFilter = new GradientGlowFilter(0, 0, colors, alphas, ratios, 30, 30, 1, 2, "full", true);
-
-
var circles:Shape = new Shape();
-
-
for (var i:int = 0; i<30; i++){
-
with(circles.graphics) beginFill(0xFF0000), drawCircle(Math.random()*500, Math.random()*400,10+Math.random()*40);
-
}
-
addChild(circles);
-
-
circles.filters = [filter];
I don't see GradientGlowFilter used much. But with some tweaking you can probably get some decent stuff out of it.
Posted in Graphics | Also tagged actionscript |