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 Tree

// forked from AceDecade's Dynamic Outline
package{
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	import flash.text.TextField;
	import flash.utils.getTimer;
	
	public class FlashTest extends Sprite{
		public var circles:Number = 40;
		public var maxx:Number = 50;
		public var maxy:Number = 50;
		public var maxsize:Number = 30;
		public var minsize:Number = 20;
		public var maxspeed:Number = 1;
		public static const DEG_RAD:Number = Math.PI/180;
		public var timer:Number = 0;
		
		public var steps:Number = 360;
		public var validity:Number = 1;
		public var cloudcolor:uint = 0x99cc99;
		public var linewidth:Number = 4;
		
		public var easydraw:Boolean = false;
		
		public var cloud:Sprite = new Sprite();
		public var Circles:Array = new Array();
		public var fps:TextField = new TextField();
		public function FlashTest(){
			addChild(cloud);
			addChild(fps);
			fps.x = -stage.stageWidth/2;
			fps.y = -stage.stageHeight/2;
			fps.height = 15;
			fps.width = 50;
			steps = 360/steps;
			
			stage.addEventListener(MouseEvent.MOUSE_DOWN,mousedown);
			
			x = stage.stageWidth/2;
			y = stage.stageHeight/2;
			
			init();
                        render();
		}
		public function init():void{
			for(var i:int=0;i<circles;i++){
				var W:Number = range(maxx,-maxx);
				var H:Number = range(maxy,-maxy);
				var S:Number = range(maxsize,minsize);
				var VX:Number = range(maxspeed,-maxspeed);
				var VY:Number = range(maxspeed,-maxspeed);
				Circles.push([W,H,S,Math.pow(S,2),VX,VY]);
			}
		}
		public function render():void{
                        with(cloud.graphics){
                            lineStyle(linewidth,0x000000,1);
                            beginFill(0xb1937b);
                            moveTo(-15,0);
                            curveTo(0,80,-20,130);
                            curveTo(0,125,20,130);
                            curveTo(0,80,15,0);
                            endFill();
                        }
			for(var i:int=0;i<circles;i++){
				with(cloud.graphics){
					lineStyle(0,0x000000,0);
					beginFill(cloudcolor);
					drawCircle(Circles[i][0],Circles[i][1],Circles[i][2]);
					endFill();
					lineStyle(linewidth,0x000000,1);
				}
				var dx:Number=0;
				var dy:Number=0;
				var mark:Boolean = false;
				for(var j:Number=0;j<=360;j+=steps){
					var X:Number = Circles[i][0]+Math.cos(j*DEG_RAD)*(Circles[i][2]+validity);
					var Y:Number = Circles[i][1]+Math.sin(j*DEG_RAD)*(Circles[i][2]+validity);
					var h:Boolean = false;
					for(var k:int=0;k<circles;k++){
						var d:Number = Math.pow(X-Circles[k][0],2)+Math.pow(Y-Circles[k][1],2);
						if(d < Circles[k][3]){
							k = circles;
							h = true;
						}
					}
					if(!h){
						if(easydraw){
							X = Circles[i][0]+Math.cos(j*DEG_RAD)*Circles[i][2];
							Y = Circles[i][1]+Math.sin(j*DEG_RAD)*Circles[i][2];
							with(cloud.graphics){
								drawCircle(X,Y,1);
							}
						}else{
							if(mark){
								cloud.graphics.moveTo(dx,dy);
								dx = Circles[i][0]+Math.cos(j*DEG_RAD)*Circles[i][2];
								dy = Circles[i][1]+Math.sin(j*DEG_RAD)*Circles[i][2];
								cloud.graphics.lineTo(dx,dy);
							}else{
								dx = Circles[i][0]+Math.cos(j*DEG_RAD)*Circles[i][2];
								dy = Circles[i][1]+Math.sin(j*DEG_RAD)*Circles[i][2];
								mark = true;
							}
						}
					}else{
						mark = false;
					}
				}
			}
		}
		public function mousedown(e:MouseEvent):void{
			reset();
			render();
		}
		public function reset():void{
			cloud.graphics.clear();
			Circles = new Array();
			init();
		}
		public function range(M:Number,m:Number=0):Number{
			return Math.random()*(M-m)+m;
		}
	}
}