flash on 2012-9-20
♥0 |
Line 89 |
Modified 2012-09-20 21:32:53 |
MIT License
archived:2017-03-30 22:59:26
ActionScript3 source code
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/uUeT
*/
package {
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
graphics.clear();
graphics.lineStyle(1,0);
var rn:Node;
rn = new Node(null);
rn.x = 30;
rn.y = 30;
rn.w = 300;
rn.h = 300;
rn.test();
rn.draw(graphics);
}//ctor
}//classend
}
import flash.display.Graphics;
internal class Node
{
public var p:Node;
public var x:Number = 0;
public var y:Number = 0;
public var w:Number = 0;
public var h:Number = 0;
public var depth:int = 0;
public var col:uint = 0;
public var vecChild:Vector.<Node>;
public function Node(par:Node)
{
p = par;
if (p == null) { depth = 0;}
else { depth = p.depth+1;}
col = Math.random() * 0xFFffFFff;
}//ctor
public function test(maxd:int=4):void
{
makeChild();
var i:int;
var num:int;
var n:Node;
num = vecChild.length;
for (i = 0; i < num; i++)
{
n = vecChild[i];
if (Math.random() < 0.75 && depth <maxd)
{ n.test(maxd); }
}//nexti
}//test
public function draw(g:Graphics):void
{
g.beginFill(col,0.5);
g.drawRect(x,y,w,h);
g.endFill();
if (vecChild == null) { return; }
var i:int;
var num:int;
var n:Node;
num = vecChild.length;
for (i = 0; i < num ;i++)
{
n= vecChild[i];
n.draw(g);
}
}//draw
public function makeChild():void
{
vecChild = new Vector.<Node>;
var i:int;
var k:int;
var kw:Number;
var kh:Number;
var n:Node;
kw = w * 0.5;
kh = h * 0.5;
for (i = 0; i < 2; i++)
{
for (k = 0; k < 2; k++)
{
n = new Node(this);
n.x = (k * kw) + x;
n.y = (i * kh) + y;
n.w = kw;
n.h = kh;
vecChild.push(n);
}//nextk
}//nexti
}//makechild
};//classend