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

Chaos Tree

Get Adobe Flash player
by AceDecade 13 Jan 2010
    Embed
package{
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.events.*;
	import flash.ui.Mouse;
	public class FlashTest extends Sprite {
		public var Branches:Array;
		public var angle:Number;
		public var shortRate:Number;
		public var wide:Number;
		public var max:Number;
		public var rmax:Array;
		public var rrate:Number;
		public var initLength:Number;
		public var color:uint;
		public var cvar:Array;
		public function FlashTest() {
			stage.addEventListener(MouseEvent.MOUSE_DOWN,mousedown);
			loadTree(1);
			drawTree();
		}
		public function mousedown(e:MouseEvent):void{
			drawTree();
		}
		public function drawTree():void{
			with(graphics){
				clear();
				lineStyle(wide,color,1);
				moveTo(stage.stageWidth/2,stage.stageHeight);
				lineTo(stage.stageWidth/2,stage.stageHeight-initLength);
			}
			Branches = new Array([new Point(stage.stageWidth/2,stage.stageHeight-initLength),initLength,-Math.PI/2,wide,color]);
			for(var i:int=0;i<max;i++){
				drawBranches();
				if(Branches.length == 0){
					i = max;
				}
			}
		}
		public function drawBranches():void{
			var A:Array = new Array();
			for(var i:int=0;i<Branches.length;i++){
				var r:int = Math.floor(Math.random()*rmax[0])+rmax[1];
				var b:Array = Branches[i];
				var X:Number = b[0].x;
				var Y:Number = b[0].y;
				var d:Number = b[1];
				var w:Number = b[3];
				var c:uint = b[4];
				if(w > 0){
					for(var k:int=0;k<3;k++){
						var temp:uint = cvar[k]+((c>>16-8*k) & 0xff);
						if(temp < 255 && temp > 0){
							c += (cvar[k]<<16-8*k) & 0xff;
						}
					}
					for(var j:int=0;j<r;j++){
						var recursive:int = Math.floor(Math.random()*rrate);
						var a:Number = b[2]+Math.random()*angle-angle/2;
						var DX:Number = Math.cos(a)*d;
						var DY:Number = Math.sin(a)*d;
						if(recursive > 0){
							d = d*shortRate;
							w -= 1;
						}
						with(graphics){
							lineStyle(w,c,w/wide);
							moveTo(X,Y);
							lineTo(X+DX,Y+DY);
						}
						A.push([new Point(X+DX,Y+DY),d,a,w,c]);
					}
				}
			}
			Branches = A;
		}
		public function loadTree(n:int):void{
			if(n == 0){
				//stickler
				angle = Math.PI/4;
				shortRate = 0.7;
				wide = 8;
				max = 20;
				rmax = new Array(2,2);
				rrate = 4;
				initLength = stage.stageHeight/6;
				color = 0x333333;
				cvar = new Array(10,10,12);
			}else if(n == 1){
				//hagbush
				angle = Math.PI*0.7;
				shortRate = 0.7;
				wide = 8;
				max = 20;
				rmax = new Array(2,2);
				rrate = 6;
				initLength = stage.stageHeight/6;
				color = 0x333333;
				cvar = new Array(10,10,12);
			}else if(n == 2){
				//average
				angle = Math.PI/2;
				shortRate = 0.7;
				wide = 10;
				max = 20;
				rmax = new Array(2,2);
				rrate = 4;
				initLength = stage.stageHeight/5;
				color = 0x333333;
				cvar = new Array(10,10,12);
			}else if(n == 3){
				//untitled
				angle = Math.PI/4;
				shortRate = 0.7;
				wide = 8;
				max = 20;
				rmax = new Array(2,2);
				rrate = 4;
				initLength = stage.stageHeight/6;
				color = 0x333333;
				cvar = new Array(10,10,12);
			}else if(n == 4){
				//untitled
				angle = Math.PI/4;
				shortRate = 0.7;
				wide = 8;
				max = 20;
				rmax = new Array(2,2);
				rrate = 4;
				initLength = stage.stageHeight/6;
				color = 0x333333;
				cvar = new Array(10,10,12);
			}
		}
	}
}