It lags on the web, but it's very fast as a swf file. Anyway, it's sort of a test. The test goes like this:
package
{
import flash.display.MovieClip;
import flash.events.*;
public class Particle extends MovieClip
{
private var windX:Number = 0;
private var windY:Number = 0;
private var brownianMotion:Number = 1;
private var sq:Number;
private var maxSpeed:Number = 4;
private var growthFac:Number = 0.18;
private var kill:Boolean = false;
public function Particle()
{
addEventListener(Event.ENTER_FRAME,loop);
this.scaleX = 0;
this.scaleY = 0;
}
private function death()
{
if (kill)
{
removeEventListener(Event.ENTER_FRAME,loop);
stage.removeChild(this);
}
}
private function loop(e:Event):void
{
if (growthFac > 0)
{
growthFac -= 0.01;
this.scaleX += growthFac;
this.scaleY += growthFac;
}
windX+=(Math.random()-0.5)*brownianMotion;
windY+=(Math.random()-0.5)*brownianMotion;
sq = windX*windX + windY*windY;
if (sq > maxSpeed)
{
windX = windX/Math.sqrt(sq)*Math.sqrt(maxSpeed);
windY = windY/Math.sqrt(sq)*Math.sqrt(maxSpeed);
}
this.y += windY;
this.x += windX;
windY -= 0.1;
if (this.x > stage.stageWidth)
{
windX *= -1;
}
if (this.x < 0)
{
windX *= -1;
}
if (this.y > stage.stageHeight)
{
windY *= -1;
}
if (this.y < 0)
{
windY *= -1;
}
this.alpha -= 0.005;
if (this.alpha <= 0)
{
kill = true;
death();
}
}
}
}
and this
package
{
import flash.display.MovieClip;
import flash.events.*;
public class Spark extends MovieClip
{
private var gravity:Number = -1;
private var acX:Number = 0;
private var acY:Number = -7;
private var bounced:Boolean = false;
private var prevX:Number;
private var prevY:Number;
private var currX:Number;
private var currY:Number;
private var speedX:Number;
private var speedY:Number;
private var rotVal:Number;
public function Spark()
{
acX += (Math.random()-0.5)*10;
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void
{
acY -= gravity;
prevX = this.x;
prevY = this.y;
this.y += acY;
this.x += acX;
currX = this.x;
currY = this.y;
speedX = currX - prevX;
speedY = currY - prevY;
rotVal = Math.atan2(speedY,speedX)*180/Math.PI;
this.rotation = rotVal;
if (this.y > stage.stageHeight)
{
acY*=-1;
bounced = true;
}
if (bounced)
{
if (acY < 1)
{
this.alpha -= 0.1;
if (this.alpha <= 0)
{
removeEventListener(Event.ENTER_FRAME, loop);
stage.removeChild(this);
}
}
}
}
}
}