In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

particle test

Get Adobe Flash player
by deform 07 Feb 2010
/**
 * Copyright deform ( http://wonderfl.net/user/deform )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/leR1
 */

package {
	import flash.geom.Point;
	import flash.filters.BlurFilter;
	import flash.text.TextField;
	import flash.geom.Rectangle;
	import flash.geom.ColorTransform;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
    import flash.display.Sprite;
    [SWF(width = "465", height = "465", backgroundColor = "0xffffff", frameRate = "60")]
    
    public class FlashTest extends Sprite {
    		private static const WIDTH:Number = 465;
    		private static const HEIGHT:Number = 465;
    		private static const PARTICLE_MAX:Number = 1500;
    		
    		private var tf:TextField;
    		private var canvas:BitmapData;
    		private var fxbmd:BitmapData;
    		private var particles:Array;
    		private var cTrs:ColorTransform;
    		private var cTrs2:ColorTransform;
    		private var blur:BlurFilter;
    		private var rect:Rectangle;
    		private var point:Point;
    		private var testCounter:Number = 0;
    		
    		private var mx:Number;
    		private var my:Number;
    		
        public function FlashTest() {
            // write as3 code here..
            
            cTrs = new ColorTransform(1, 1, 1, 0.9);
            cTrs2 = new ColorTransform(1, 1, 1, 0.95);
            blur = new BlurFilter(5, 5, 2);
            rect = new Rectangle(0, 0, WIDTH, HEIGHT);
            point = new Point(0, 0);
            
            canvas = new BitmapData(WIDTH, HEIGHT);
            addChild(new Bitmap(canvas));
            fxbmd = new BitmapData(WIDTH, HEIGHT);
            addChild(new Bitmap(fxbmd));
            
            tf = new TextField();
            addChild(tf);
            
        		particles = [];
            createParticle();
            
            addEventListener(Event.ENTER_FRAME, _upDate);
        }
        
        private function createParticle():void {
        		var invertNum:Number = int(Math.random()*2-1+1)-1;
            for(var i:int=0; i<PARTICLE_MAX; i++){
	            var p:Particle = new Particle();
	            p.x = Math.sin(i/180)*130 + WIDTH/2;
	            p.y = Math.cos(i/180)*130 + HEIGHT/2;
		        p.tx = (Math.sin(i/180)*Math.PI+Math.random()*2-1) * Math.random();
		        p.ty = (Math.cos(i/180)*Math.PI+Math.random()*2-1) * Math.random();
	            p.c = 0x0;
	            particles.push(p);
            }
        }
        
        private function _upDate(e:Event):void {
        		tf.text = "particles : "+particles.length;
        		canvas.lock();
			canvas.colorTransform(rect, cTrs);
        		for(var i:int=0; i<particles.length; i++){
        			particles[i].x += particles[i].tx;
        			particles[i].y += particles[i].ty;
				canvas.setPixel32(particles[i].x, particles[i].y, 0xff000000);
				if(particles[i].x > WIDTH || particles[i].x <0 || particles[i].y > HEIGHT || particles[i].y < 0) particles.splice(i, 1);
        		}
        		fxbmd.lock();
        		fxbmd.draw(canvas);
        		fxbmd.colorTransform(rect, cTrs2);
        		fxbmd.applyFilter(fxbmd, rect, point, blur);
        		fxbmd.unlock();
	        canvas.unlock();
	        if(particles.length < PARTICLE_MAX/2) createParticle();
        }
    }
}


    
class Particle {
	public var x:Number;
	public var y:Number;
	public var tx:Number;
	public var ty:Number;
	public var g:Number;
	public var c:Number;
}