particleDispersion
♥0 |
Line 44 |
Modified 2010-02-10 02:34:59 |
MIT License
archived:2017-03-20 02:30:46
ActionScript3 source code
/**
* Copyright 0xABCDEF ( http://wonderfl.net/user/0xABCDEF )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9Bla
*/
package {
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.MouseEvent;
import net.hires.debug.Stats;
[SWF(width=465,height=465,backgroundColor=0x000000,frameRate=120)]
public class particleDispersion extends Sprite {
public function particleDispersion(){
var bd:BitmapData = new BitmapData(550,400,true,0x00000000);
var b:Bitmap = new Bitmap(bd);
var a:Array = new Array();
var i:int;
function polar(d:Number):Point{
var xm:Number = Math.cos(d);
var ym:Number = Math.sin(d);
return (new Point(xm, ym));
}
function ef(e:Event):void{
bd.fillRect(new Rectangle(0,0,465,465),0x00000000);
for(i = 0; i<a.length; i++){
bd.setPixel32(a[i].x,a[i].y,a[i].c);
a[i].x += polar(a[i].d).x;
a[i].y += polar(a[i].d).y;
if((a[i].x > 465)||(a[i].x < 0)||(a[i].y > 465)||(a[i].y < 0)){
a.splice(i,1);
}
}
}
function mc(e:MouseEvent):void{
for(i = 1; i<=360; i++){
a.push({x:e.localX,y:e.localY,c:0xFFFFFFFF,d:Math.random()*i});
}
}
stage.addEventListener(MouseEvent.CLICK, mc);
stage.addEventListener(Event.ENTER_FRAME, ef);
stage.addChild(b);
stage.addChild(new Stats());
}
}
}