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のアレ

tree like a processing sample
@author naoto.koshikawa
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 = "24")] 
	
	/**
	 * tree like a processing sample
	 * @author naoto.koshikawa
	 */
	public class Main4 extends Sprite
	{
		// _____________________________________________________ Property
		/** base container which virtual stage */
		private var _base:Sprite;
		
		/** tree angle in radian */
		private var _radian: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 + _radian, radius * 0.66);
			draw(end, radian - _radian , radius * 0.66);
		}
		
		// _____________________________________________________ Listener
		/**
		 * enter frame event listener
		 * @param	event
		 */
		private function enterFrameListener(event:Event):void
		{
			_radian = (1- (mouseX / stage.stageWidth)) * (Math.PI / 2) - Math.PI / 2;
			_base.graphics.clear();
			draw(new Point(0, 0), -Math.PI/2, stage.stageHeight / 3 * (1-(mouseY / stage.stageHeight)));
		}
	}
}