Prev | Current Page 647 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

NORTH + Random.float(-this.angle/8, this.angle/8);
if(width == null)
width = this.width;
// under those limits do not generate any more branches
if(width < 1 || len < 2)
return;
// determine the coords of the end of the branch
var nx = x+Math.cos(ang)*len;
var ny = y+Math.sin(ang)*len;
// draw the branch
container.lineStyle(width, color, #if flash9 1 #else flash 100 #end);
container.moveTo(x, y);
container.lineTo(nx, ny);
// generate the sub-branches
for(i in 0...Random.int(1, branches))
Chapter 12: Building Interactive Content with Flash
339
{
generate(
nx,
ny,
Random.float(len*2/3, len),
Random.float(-angle/2, angle/2)+ang,
width-1);
}
}
}
class Random
{
public static function float(min : Float, max : Float) : Float
{
return Math.random()*(max-min)+min;
}
public static function int(min : Int, max : Int) : Int
{
return Math.floor(float(min, max));
}
}
class Angle
{
public static var NORTH = -Math.PI/2;
public static var D120 = Math.PI*2/3;
public static var D90 = Math.PI/2;
public static var D60 = Math.


Pages:
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659