fractal boxes
package {
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.TimerEvent;
import flash.utils.Timer;
[SWF(backgroundColor=0xffffff, frameRate=24)]
public class RecursiveFill extends Sprite
{
private var aree:Array;
public function RecursiveFill()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
aree = new Array();
aree.push({x:0, y:0, w:stage.stageWidth, h:stage.stageHeight, depth:0});
var t:Timer = new Timer(10);
t.addEventListener(TimerEvent.TIMER, step);
t.start();
}
private function step(e:TimerEvent):void {
if (aree.length == 0) (e.target as Timer).stop();
var i:Object = aree.shift();
if (i.d == 6) return;
var s:Shape = new Shape();
s.graphics.lineStyle(1, 0);
s.graphics.beginFill(Math.random() * 0xFFFFFF, 1);
s.graphics.drawRect(i.x, i.y, i.w, i.h);
s.graphics.endFill();
addChild(s);
//aree.push({x:i.x, y:i.y, w:i.w /2, h:i.h /2, depth:i.depth+1});
aree.push({x:i.x + i.w /2, y:i.y, w:i.w /2, h:i.h /2, depth:i.depth+1});
aree.push({x:i.x, y:i.y + i.h /2, w:i.w /2, h:i.h /2, depth:i.depth+1});
aree.push({x:i.x + i.w /2, y:i.y + i.h /2, w:i.w /2, h:i.h /2, depth:i.depth+1});
}
}
}