TreeCurve 木に見えるフラクタル ton forked:2favorite:3lines:44license : All rights reserved modified : 2009-01-14 03:26:41 Embed Tweet //木に見えるフラクタル package { import flash.display.Sprite; import flash.events.*; import flash.geom.Point; [SWF(backgroundColor=0x000000)] public class TreeCurve extends Sprite { private var list:Array = new Array(); private const SIZE:int = 465; private const RAD:Number = Math.PI/8; private const a:Number = 0.75; function TreeCurve() { addLine(new Line(new Point(SIZE/2, SIZE), new Point(SIZE/2, SIZE*4/5))); stage.addEventListener(Event.ENTER_FRAME,onEnterFrameHandler); } private function onEnterFrameHandler(event:Event):void { var line:Line=list[0]; list.splice(0, 1); addLine(new Line(line.endP, new Point(line.endP.x + line.distance * a * Math.cos(line.angle + RAD), line.endP.y + line.distance * a * Math.sin(line.angle+RAD)))); addLine(new Line(line.endP, new Point(line.endP.x + line.distance * a * Math.cos(line.angle - RAD), line.endP.y + line.distance * a * Math.sin(line.angle - RAD)))); } private function addLine(line:Line):void { list.push(line); addChild(line); } } } import flash.display.Sprite; import flash.geom.Point; class Line extends Sprite { public var startP:Point; public var endP:Point; public var distance:Number; public var angle:Number; function Line(startP:Point, endP:Point) { this.startP = startP; this.endP = endP; angle = Math.atan2(endP.y-startP.y, endP.x-startP.x); distance = Point.distance(startP, endP); graphics.lineStyle(0,0xffffff); graphics.moveTo(startP.x, startP.y); graphics.lineTo(endP.x, endP.y); graphics.endFill(); } } Code Fullscreen Preview Fullscreen web_shiino Yukulele : arbrefractalarbre blackwater : 画大树 arbre fractal Point.distance splice Math.atan2 Math.cos addEventListener push addChild Math.PI Point Math.sin Event.ENTER_FRAME Array Event int Sprite Number sort new page view favorite forked pv266 forked from: TreeCurve azAZ09 forked:0 favorite:0lines:44 (diff:1) pv362 forked from: TreeCurve Yukulele forked:0 favorite:1lines:47 (diff:16) tag: 木