package { import flash.display.*; import flash.events.*; import flash.geom.Point; import flash.filters.GlowFilter; [SWF(backgroundColor = "0xFFFFFF",frameRate = "100")] public class Main extends Sprite { private var shape:Shape; private var source:BitmapData; public function Main() { shape = new Shape ; source = new BitmapData(1000,1000,false,0xFFFFFF); addChild(new Bitmap(source)); this.addEventListener(Event.ENTER_FRAME,onEnterFrame); } private function onEnterFrame(e:Event):void { shape.graphics.clear(); creatTree(shape.graphics,400,850,90,180,5); creatTree(shape.graphics,400,850,45,100,4); creatTree(shape.graphics,400,850,135,100,4); step += Math.PI / 80 % Math.PI; source.fillRect(source.rect,0xFFFFFF); source.draw(shape); } private var step:Number = 0.0; private static const toRadian:Number = Math.PI / 180; private function creatTree(g:Graphics,px:Number,py:Number,angle:Number,len:Number,n:int):void { if (n > 0) { angle += 3 * Math.cos(step) - 2; var x1:Number = px + 0.1 * len * Math.cos(angle * toRadian); var y1:Number = py - 0.1 * len * Math.sin(angle * toRadian); var x2:Number = px + len * Math.cos(angle * toRadian); var y2:Number = py - len * Math.sin(angle * toRadian); drawLine(g,n - 1,px,py,x2,y2); var a_l:Number = angle + 25; var a_r:Number = angle - 25; var lenlen = len * 2 / 3; creatTree(g,x2,y2,angle - 3 * Math.sin(step),len,n - 1); creatTree(g,x1,y1,a_l,len * 2 / 3,n - 1); creatTree(g,x1,y1,a_r,len * 2 / 3,n - 1); creatTree(g,x2,y2,a_l,len * 2 / 3,n - 1); creatTree(g,x2,y2,a_r,len * 2 / 3,n - 1); } } private function drawLine(g:Graphics,n:int,x1:Number,y1:Number,x2:Number,y2:Number):void { g.lineStyle(n,0x006600); g.moveTo(x1,y1); g.lineTo(x2,y2); } } }