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

Treeのアレ with a twist :)

tree like a processing sample
@author naoto.koshikawa
// forked from naoto5959's treeのアレ
package
{
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	[SWF(width = "464", height = "465", backgroundColor = "0x000000", frameRate = "20")] 
	
	/**
	 * tree like a processing sample
	 * @author naoto.koshikawa
	 */
	public class Main4 extends Sprite
	{
		// _____________________________________________________ Property
		/** base container which virtual stage */
		private var _base:Sprite;
		
		/** symmetry is boring */
		private var _radianLt:Number;
		private var _radianRt:Number;

		
		// _____________________________________________________ Method
		/**
		 * constructor
		 */
		public function Main4() 
		{
			createBase();
			addEventListener(Event.ENTER_FRAME, enterFrameListener);
		}
		
		/**
		 * create base container which move center position in virtual
		 */
		private function createBase():void
		{
			_base = new Sprite();
			_base.x = stage.stageWidth / 2;
			_base.y = stage.stageHeight;
			var dotData:BitmapData = new BitmapData(2, 2, true, 0x00000000);
			dotData.setPixel32(0, 0, 0x33000000 | 0x00FFFFFF * Math.random());
			var dot:Shape = new Shape();
			dot.graphics.beginBitmapFill(dotData);
			dot.graphics.drawRect(-_base.x, -_base.y, stage.stageWidth, stage.stageHeight);
			_base.addChild(dot);
			addChild(_base);
		}
		
		/**
		 * draw line method
		 */
		private function draw(start:Point, radian:Number, radius:Number):void
		{
			if (radius < 3) return;
			
			var gr:Graphics = _base.graphics;
			gr.lineStyle(1, 0x111111 * Math.random() + 0xEEEEEE);
			gr.moveTo(start.x, start.y);
			var end:Point = new Point(start.x + Math.cos(radian) * radius, start.y + Math.sin(radian) * radius);
			gr.lineTo(end.x, end.y);
			gr.endFill();
				
			draw(end, radian + _radianLt, radius * 0.66);
			draw(end, radian - _radianRt, radius * 0.66);
		}
		
		// _____________________________________________________ Listener
		/**
		 * enter frame event listener
		 * @param	event
		 */
		private function enterFrameListener(event:Event):void
		{
			var radian:Number = (1- (mouseY / stage.stageHeight)) * (Math.PI / 2) - Math.PI / 2;
			var twist:Number = (mouseX - stage.stageWidth / 2) / stage.stageWidth; // -0.5..+0.5
			_radianLt = (1 - twist) * radian;
			_radianRt = (1 + twist) * radian;

			_base.graphics.clear();
			draw(new Point(0, 0), -Math.PI/2, 150);
		}
	}
}