Ed ecco la classe completa:
// Fern Fractal Nicola Sirago - an - Jim Bumgardner 2008 -port package { import flash.geom.*; import GeomUtil; import flash.events.Event; import flash.display.DisplayObject; import flash.display.Sprite; public class FernSprite2 extends Sprite { var maxLevels:Number// = 6; var initBendAngle:Number// = 15; var initBranchAngle:Number// = 37; var trunkRatio:Number// = .1; var branchRatio:Number// = .4; var heightScale:Number// = 2.5; var regularity:Number// = 1; var offshoot:Number// = 1; public function FernSprite2(initObj) { maxLevels = initObj.maxLevels; initBendAngle = initObj.initBendAngle; initBranchAngle = initObj.initBranchAngle; trunkRatio = initObj.trunkRatio; branchRatio = initObj.branchRatio; heightScale = initObj.heightScale; regularity = initObj.regularity; offshoot = initObj.offshoot; initObj.parMC.addChild(this); } public function drawFern(p,a,rad,level) { var c:Point = new Point(p.x + Math.cos(a) * rad * trunkRatio, p.y + Math.sin(a) * rad * trunkRatio); p.height = Point.distance(new Point (p.x,p.y), c); p.width = (level + 1)*trunkRatio*30 p.rotation = GeomUtil.radToGrad(a)-90; this.addChild(p); if (level > 0) { a += bendAngle; level--; var b1:ramo = new ramo; var b2:ramo = new ramo; var b3:ramo = new ramo; b1.x = b2.x = b3.x = c.x; b1.y = b2.y = b3.y = c.y; if(randRange(0,offshoot)) drawFern(b1, a - branchAngle * randRange2(1, regularity), rad * branchRatio * randRange2(1, regularity), level); if(randRange(0,offshoot)) drawFern(b2, a + branchAngle * randRange2(1, regularity), rad * branchRatio * randRange2(1, regularity), level); if(randRange(0,offshoot)) drawFern(b3,a * randRange2(1, regularity),rad*antiTrunkRatio * randRange2(1, regularity),level); }else { var f:foglie = new foglie; f.x = c.x; f.y = c.y; // f.rotation = p.rotation if(randRange(0,offshoot)) this.addChild(f); } } public function redrawFern() { bendAngle = initBendAngle*Math.PI/180; branchAngle = initBranchAngle*Math.PI/180; lastMaxLevels = maxLevels; antiTrunkRatio = 1-trunkRatio; startAngle = -Math.PI/2; var b:t2 = new t2; drawFern(b, startAngle, heightScale, maxLevels); } public static function randRange(min:Number, max:Number):Number { var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min; return randomNum; } public static function randRange2(min:Number, max:Number):Number { if (min == max) return min var d = 0 while (d == 0) { d = randRange( -1, 1) } var randomNum:Number =Math.abs( Math.random() * (max - min) + min * d); return randomNum; } } }
Per modificare le texture basta modificare i disegni all'interno dei movieclip "ramo" e "foglie"
0 comments:
Posta un commento