
Код AS3:
package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
public class Main extends Sprite
{
public function Main():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:MouseEvent):void
{
var g:Graphics = this.graphics;
g.lineStyle(1, 0);
fractal(200, 200, 500, 300, 10);
}
private function fractal(x1:int, y1:int, x2:int, y2:int, depth:int):void
{
var tx:int;
var ty:int;
if (depth == 0)
{
var g:Graphics = this.graphics;
g.drawCircle(x1, y1, 2);
g.drawCircle(x2, y2, 2);
return;
}
tx = (x1 + x2) / 2 + (y2 - y1) / 2;
ty = (y1 + y2) / 2 - (x2 - x1) / 2;
fractal(x2, y2, tx, ty, depth - 1);
fractal(x1, y1, tx, ty, depth - 1);
}
}
}