More fun with the BitmapData class.
This is a really clean… in my opinion really slick, Fireworks effect using nothing more than BitmapData.
The Code:
import flash.display.BitmapData;
import flash.filters.DropShadowFilter;
import flash.geom.Point;
var GRAVITY:Number = 0.98;
var bgcolor:Number = 0x000000000;
var fadecolor:Number = 0x22000000;
var width:Number = 400;
var height:Number = 300;
var x:Number = Stage.width/2;
var y:Number = Stage.height/2;000
var container:MovieClip = this.createEmptyMovieClip("container", 10);
var canvas:BitmapData = new BitmapData(width, height, true, bgcolor);
var white:BitmapData = new BitmapData(width, height, true, fadecolor);
var background:BitmapData = new BitmapData(Stage.width, Stage.height, false, 0xFF333333);
var shadow:DropShadowFilter = new DropShadowFilter(1, 45, 0x444444, 100, 5, 5, 3, 3, false, false, false);
attachBitmap( background, 99 );
container.attachBitmap( canvas, 100 );
container._x = x - width/2;
container._y = y - height/2;
container.swapDepths( 100 );
container.filters = [shadow];
var mortar : Point = new Point();
var mortarVY : Number = 2;
var mortarVX : Number = 0;
moveMortar();
var blowUpIntervalID = setInterval(this, "blowUp", 3000);
function blowUp()
{
var particles:Number = Math.round((Math.random() * 180) + 20);
trace(particles);
for (var i:Number=0; i<particles; i++)
{
var x:Number = mortar.x;// - container._x;
var y:Number = mortar.y;// - container._y;
generateParticle(x, y);
}
moveMortar();
}
function moveMortar() : Void
{
mortar.x = (Math.random() * container._width);
mortar.y = container._height;
mortarVY = Math.round( Math.random() * (4-1) ) + 1;
mortarVX = (Math.random() * 2)- 1;
}
function onEnterFrame()
{
canvas.draw( white );
mortar.x += mortarVX;
mortar.y -= mortarVY;
mortarVY *= GRAVITY;
canvas.setPixel( mortar.x, mortar.y, 0xFFFFFF );
}
function generateParticle(startX:Number, startY:Number) : Void
{
var point : Object = new Object();
point.x = startX;
point.y = startY;
point.vy = -Math.random() * 10 - 5;
point.vx = Math.random() * 10 - 5;
point.color = Math.random() * 0xFFFFFF;
point.animID = setInterval(point, "move", 40);
point.move = function()
{
canvas.setPixel( this.x, this.y, this.color );
this.x += this.vx;
this.y += this.vy;
this.vy += GRAVITY;
if (this.y > Stage.height)
{
clearInterval( point.animID );
delete this;
}
}
}
An example can be seen here:
http://createage.com/actionscript_org/Fireworks.html
Tell me what you guys think, and feel free to use this for whatever purpose you see fit.
Take Care.
_Michael