Actionscript:
-
var circs:Array = []
-
var circNum:int = 600;
-
addEventListener(Event.ENTER_FRAME, onAdd);
-
function onAdd(evt:Event):void {
-
if (circs.length <circNum){
-
makeGrowable();
-
}
-
}
-
-
function makeGrowable(){
-
-
var s:MovieClip = MovieClip(addChild(new MovieClip()));
-
s.x = Math.random() * stage.stageWidth;
-
s.y = Math.random() * stage.stageHeight;
-
with(s.graphics){
-
lineStyle(0,0);
-
drawCircle(0,0,10);
-
}
-
s.scaleX = s.scaleY = 0;
-
circs.push(s);
-
s.addEventListener(Event.ENTER_FRAME, onScaleUp);
-
}
-
-
function onScaleUp(evt:Event):void {
-
var c:MovieClip = MovieClip(evt.currentTarget);
-
c.scaleX = c.scaleY += 0.05;
-
for (var i:int = 0; i<circs.length; i++){
-
var circ:MovieClip = circs[i];
-
if (circ != c){
-
var amt:Number = circ.width/2 + c.width/2;
-
var dx:Number = circ.x - c.x;
-
var dy:Number = circ.y - c.y;
-
var dist:Number = Math.sqrt(dx * dx + dy * dy);
-
if (amt> dist){
-
c.removeEventListener(Event.ENTER_FRAME, onScaleUp);
-
if (c.scaleX <0.1){
-
if (contains(c)){
-
removeChild(c);
-
}
-
}
-
}
-
}
-
-
}
-
}
Circle fitting is one of those things I've never bothered to do... today I figured I'd give it a try and this is what I came up with. I posted it on wonderfl: