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

code on 2008-12-24

Get Adobe Flash player
by kamipoo 24 Dec 2008
    Embed
package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
    [SWF(width = "465", height = "465", backgroundColor = "0x000000", frameRate = "60")]
	
	public class Test extends Sprite {
		
		private var _particles:Vector.<Particle>;
		private var _canvas:BitmapData;
		private var _glow:BitmapData;
		private var _filter:BlurFilter;
		private var _mat:Matrix;
		
		public function Test() {
			super();
			init();
		}
		
		private function init():void {
			_particles = new Vector.<Particle>();
			_canvas = new BitmapData(465, 465, true, 0x0);
			_glow = new BitmapData(465/4, 465/4, true, 0x0);
			
			_filter = new BlurFilter(2, 2, 4);
			_mat = new Matrix();
			_mat.scale(1/4, 1/4);
			
			//this.addChild(new Bitmap(_canvas) as Bitmap);
			var bm:Bitmap = this.addChild(new Bitmap(_glow, "auto", true)) as Bitmap;
			bm.scaleX = bm.scaleY = 4;
			this.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
			this.stage.addEventListener(Event.ENTER_FRAME, enterframeHandler);
		}
		
		private function mouseMoveHandler(e:MouseEvent):void 
		{
			var i:int = 100;
			while (i--) createParticle();
		}
		
		private function createParticle():void {
			var p:Particle = new Particle();
			p.x = stage.mouseX;
			p.y = stage.mouseY;
			p.vx = (Math.random() > .5 ? 1 : -1) * Math.random() * 2;
			p.vy = (Math.random() > .5 ? 1 : -1) * Math.random() * 2;
			p.c = 0xFFFFFFFF;
			_particles.push(p);
		}
		
		private function enterframeHandler(e:Event):void {
			update();
		}
		
		private function update():void {
			this._canvas.lock();
			this._canvas.fillRect(this._canvas.rect, 0x0);
			var i:int = _particles.length;
			while (i--) {
				var p:Particle = _particles[i];
				p.vx *= .9;
				p.vy *= .9;
				p.x += p.vx;
				p.y += p.vy;
				this._canvas.setPixel32(p.x, p.y, p.c);
				if ((p.x > stage.stageWidth || p.x < 0) || (p.y < 0 || p.y > stage.stageHeight) || Math.abs(p.vx) < .01 || Math.abs(p.vy) < .01) {
					this._particles.splice(i, 1);
				}
			}
			this._canvas.unlock();
			_glow.draw(_canvas, _mat);
			_glow.applyFilter(_glow, _glow.rect, new Point(), _filter);
		}
		
	}
	
}

class Particle {
	
	public var x:Number;
	public var y:Number;
	public var vx:Number;
	public var vy:Number;
	public var s:Number;
	public var c:uint;
	
	public function Particle() {
		this.x = 0;
		this.y = 0;
		this.vx = 0;
		this.vy = 0;
		this.s = 1;
		this.c = 0xFFFFFFFF;
	}
}