package{ import flash.display.Sprite; public class Puu4 extends Sprite{ public function Puu4(){ joonista(); y=50; x=200; } public function leiaOts(algx:Number, algy:Number, vx:Number, vy:Number, koef:Number, nurk:Number):Array{ var rvx:Number=vy; var rvy:Number=-vx; var otsx:Number=algx+Math.cos(nurk)*vx*koef+Math.sin(nurk)*rvx*koef; var otsy:Number=algy+Math.cos(nurk)*vy*koef+Math.sin(nurk)*rvy*koef; return new Array(otsx, otsy); } public function joonistaOks(x1:Number, y1:Number, x2:Number, y2:Number):void{ graphics.moveTo(x1, y1); graphics.lineTo(x2, y2); var vektorx:Number=x2-x1; var vektory:Number=y2-y1; if(Math.sqrt(vektorx*vektorx+vektory*vektory)>5){ var v:Array=leiaOts(x2, y2, vektorx, vektory, 0.8, Math.PI/8); joonistaOks(x2, y2, v[0], v[1]); v=leiaOts(x2, y2, vektorx, vektory, 0.5, -Math.PI/6); joonistaOks(x2, y2, v[0], v[1]); } } public function joonista():void{ graphics.clear(); graphics.lineStyle(1, 0, 1); //paksus, värv, nähtavus joonistaOks(100, 200, 110, 150); } } }