/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/mo5M
*/
package {
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
vecRect = new Vector.<xRect>(0, false);
addRect(230-16, 230-16, 32, 32);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var vecRect:Vector.<xRect>;
public function makeRect(ax:Number, ay:Number, aw:Number, ah:Number):xRect
{
var a:xRect;
a = new xRect(); vecRect.push(a);
a.cx = ax; a.cy = ay;
a.cw = aw; a.ch = ah;
return a;
}//makerect
public function addRect(ax:Number, ay:Number, aw:Number, ah:Number, d:Number=32):xRect
{
var kx:Number; var ky:Number; var u:Number; var t:Number;
kx = ax; ky = ay;
t = Math.random() * 6.28;
if (isOver(ax, ay, aw, ah) == false) { return makeRect(ax,ay,aw,ah); }
while (d < 512)
{
for (u=0;u<6.28;u+=0.19)
{
ax = Math.cos(u+t) * d + kx;
ay = Math.sin(u+t) * d + ky;
if (isOver(ax, ay, aw, ah) == false) { return makeRect(ax,ay,aw,ah); }
}//nexti
d += 16;
}//wend
trace("couldnt add rect ");
return makeRect(ax,ay,aw,ah);
}//addrect
public function isOver(ax:Number, ay:Number, aw:Number, ah:Number):Boolean
{
var a:xRect; var i:int; var num:int;
num = vecRect.length;
for (i = 0; i < num; i += 1)
{
a = vecRect[i];
if (ax + aw < a.cx) { continue; } if (ay + ah < a.cy) { continue; }
if (a.cx + a.cw < ax) { continue; } if (a.cy + a.ch < ay) { continue; }
return true;
}//nexti
return false;
}//isover
public function addRandRect():void
{
var p:xRect; var a:xRect;
p = vecRect[ int(vecRect.length * Math.random() ) ];
p = vecRect[0];
//p = vecRect[vecRect.length - 1];
a = addRect(p.cx, p.cy, 16 + Math.random() * 8, 16 + Math.random() * 8, 32);
} //addrandrect
public function onEnter(e:Event):void
{
graphics.clear();
graphics.lineStyle(2,0x404040);
var i:int; var num:int; var a:xRect;
num = vecRect.length;
for (i = 0; i < num; i += 1)
{
a = vecRect[i];
graphics.beginFill(0xA0A0A0, 1);
graphics.drawRect(a.cx, a.cy, a.cw, a.ch);
graphics.endFill();
}//nexti
//its brute force so limit their number for now
if (vecRect.length < 256) { addRandRect(); }
}//onenter
}//classend
}
internal class xRect
{
public var cx:Number = 0; public var cy:Number = 0;
public var cw:Number = 0; public var ch:Number = 0;
}//xrect