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

Random Walking

...
@author 9re
Get Adobe Flash player
by 9re 11 May 2009
package  
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author 9re
	 */
	[SWF(backgroundColor="#000000", frameRate=30)]
	public class RandomWalk extends Sprite
	{
		private var _bd:BitmapData;
		private var _p:Point;
		private var _hue:Number;
		private var _colorV:Number = 0.02;
		private var _pointV:Number = 5.0;
		private var _shape:Shape;
		
		public function RandomWalk() 
		{
			_bd = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0);
			addChild(new Bitmap(_bd));
			
			_p = new Point(stage.stageWidth / 2, stage.stageHeight / 2);
			_shape = new Shape();
			_hue = 0;
			addEventListener(Event.ENTER_FRAME, draw);
		}
		
		private function draw(e:Event):void 
		{
			var sgn:int = (int(Math.floor(Math.random() * 1000)) % 2 == 0) ? 1 : -1;
			var direction:Number = Math.PI * 2 * Math.random();
			_hue += sgn * _colorV;
			_shape.graphics.clear();
			_shape.graphics.moveTo(0, 0);
			var matrix:Matrix = new Matrix(1, 0, 0, 1, _p.x, _p.y);
			var vec:Point = new Point(_pointV * Math.cos(direction), _pointV * Math.sin(direction));
			_p = _p.add(vec);
			_shape.graphics.lineStyle(4, hsv2rgb(_hue * 360, 0xff, 0xff));
			_shape.graphics.lineTo(vec.x, vec.y);
			_bd.draw(_shape, matrix, null);
			_bd.applyFilter(_bd, _bd.rect, new Point(), new BlurFilter(2, 2, 1));
		}
		
		private function hsv2rgb(hh:Number, ss:Number, vv:Number):uint {
			while (hh < 0) {
				hh += 360;
			}
			while (hh >= 360) {
				hh -= 360;
			}
			ss = Math.min( Math.max( ss, 0 ), 255 )/255;
			vv = Math.min( Math.max( vv, 0 ), 255 )/255;
			var rr:Number;
			var gg:Number;
			var bb:Number;
			if (ss == 0) {
				rr = vv;
				gg = vv;
				bb = vv;
			} else {
				var hi:Number = Math.floor((hh/60)%6);
				var ff:Number = (hh/60) - hi;
				var pp:Number = vv*(1-ss);
				var qq:Number = vv*(1-ff*ss);
				var tt:Number = vv*(1-(1-ff)*ss);
				trace("hi:"+hi);
				trace("ff:"+ff);
				switch (hi) {
				case 0 :
					rr = vv;
					gg = tt;
					bb = pp;
					break;
				case 6 :
					rr = vv;
					gg = 0;
					bb = pp;
					break;
				case 1 :
					rr = qq;
					gg = vv;
					bb = pp;
					break;
				case 2 :
					rr = pp;
					gg = vv;
					bb = tt;
					break;
				case 3 :
					rr = pp;
					gg = qq;
					bb = vv;
					break;
				case 4 :
					rr = tt;
					gg = pp;
					bb = vv;
					break;
				case 5 :
					rr = vv;
					gg = pp;
					bb = qq;
					break;
				default :
					trace("error");
				}
			}
			
			return uint(Math.floor(rr * 255)) << 16 | uint(Math.floor(gg * 255)) << 8 | uint(Math.floor(bb * 255));
		}

	}
}