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

forked from: 自己計測するパーティクル

/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oWBP
 */

package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
	import flash.geom.Point;
	import net.hires.debug.Stats;
    
	[SWF (backgroundColor = "0x0", frameRate = "30", width = "465", height = "465")]
    public class FlashTest extends Sprite {
    	private const numParticles: int = 300;
		private var _particles: Array;
		private var stats: Stats;
		private var bmd: BitmapData;
		private var point: Point;
		
		
        public function FlashTest() {
            // write as3 code here..
            if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
        }
		
		private function init(e: Event = null): void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			//
			
            _particles = [];
            for (var i:int = 0; i < numParticles; i++)
            {
				var p:Particle = new Particle();
				_particles.push(p);
				//addChild(p);
            }
			addChild(stats = new Stats());
			addChild(new Bitmap(bmd = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0), "auto", true));
            point = new Point();
			
            addEventListener(Event.ENTER_FRAME, loop);
		}
        
        private function loop(e:Event):void
        {
			bmd.lock();
			var b: BitmapData = new BitmapData(stats.width, stats.height, false, 0);
			var r: Number, i: int;
			b.draw(stats);
			bmd.fillRect(bmd.rect, 0);
			for (i = 0; i < numParticles; i++)
			{
				var p: Particle = _particles[i];
				p._theta += 0.01;
				r = p._theta * 10;
				r *= r;
				p.x = p._x0 + r * Math.cos(p._theta + p._theta0);
				p.y = p._y0 + r * Math.sin(p._theta + p._theta0);
				if (p.x > 465 || p.x < -60 || p.y > 465 || p.y < -80) 
				{
					p.init();
					_particles.splice(i, 1);
					_particles.unshift(p);
				}
				else 
				{
					point.x = p.x, point.y = p.y;
					bmd.copyPixels(b, b.rect, point);
				}
			}
			b.dispose();
			bmd.unlock();
        }
    }
}

class Particle 
{
	public var x: Number = 0, y: Number = 0;
	public var _x0: Number = 0, _y0: Number = 0;
	public var _theta0: Number = 0, _theta: Number = 0;
	
	public function Particle()
	{
		super();
		_x0 =200;
		_y0 =180;
		_theta0 = 2 * Math.PI * Math.random();
		_theta = 2.5 * Math.random();
	}
	
	public function init():void
	{
		x = _x0;
		y = _y0;
		_theta = 0;
		_theta0 = 2 * Math.PI * Math.random();
	}
}