Actionscript:
-
stage.frameRate = 30;
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void{
-
if (int(Math.random()*5)==1){
-
for (var i:int= 0; i<10; i++) createParticle();
-
}
-
}
-
-
function createParticle():void{
-
var s:MovieClip = new MovieClip();
-
s.graphics.beginFill(0);
-
s.graphics.drawCircle(0,0,Math.random()*10 + 2);
-
s.velX = Math.random()*10-5
-
s.velY = Math.random()*10-5
-
s.posX = s.x = 200;
-
s.posY = s.y = 200;
-
addChild(s);
-
s.addEventListener(Event.ENTER_FRAME, onRunParticle);
-
}
-
-
function onRunParticle(evt:Event):void {
-
var s:MovieClip = MovieClip(evt.currentTarget);
-
s.posX += s.velX;
-
s.posY += s.velY;
-
s.scaleX = s.scaleY -= .04;
-
if (s.scaleX <0){
-
removeChild(s);
-
s.removeEventListener(Event.ENTER_FRAME, onRunParticle);
-
}
-
s.x = s.posX;
-
s.y = s.posY;
-
}
Nothing special here. But my students are always asking me about this - in class I have them alter this code to make fire, water and abstract particle systems.