En informática existen varios términos para recursivo ya que es un término de algoritmos de programación. La idea es que un valor se va disminuyendo así mismo indefinidamente o hasta que sea suficiente para lo que se necesita.
Para nosotros y en este ejemplo es simplemente un random el cual va mostrando cómo se construye un árbol con ramas, las cuales se construyen recursivamente a sí mismos.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
//Pixelarte function halt():void { stage.removeEventListener(MouseEvent.CLICK,click); } <pre>//creamos los eventos del clic</pre> stage.addEventListener(MouseEvent.CLICK,click); var activeBranches:Array; var branches:Array; var depth:Number; //iniciamos! setup(); function setup():void { if (branches) { removeChild(branches[0]); } depth = 0; //aca creamos un brazo del arbol var branch:Sprite = getBranch(); branch.x = 550/2; branch.y = 550; addChild(branch); branches = [branch]; activeBranches = [branch]; } function click(evt:Event):void { if (depth > 8) { setup(); return; } var abs:Array = []; while (activeBranches.length > 0) { var branch:Sprite = activeBranches.pop(); var h:Number = branch.height; var child:Sprite = getBranch(); trace(branch.name); child.y = -h; child.rotation = Math.random()*20+5; branch.addChild(child); branches.push(child); abs.push(child); child = getBranch(); child.y = -h; child.rotation = Math.random()*-20-5; branch.addChild(child); branches.push(child); abs.push(child); } depth++; activeBranches = abs; } function getBranch():Sprite { var w:Number = 4-depth/2; var branch:Sprite = new Sprite(); branch.graphics.lineStyle(w,0xFFFFFF,w/3+0.15); branch.graphics.lineTo(0,Math.random()*-30-35+depth*3); branch.name = "branch"+depth; return branch; } |
Categories: Action Script 3
Wauuuuu muy interesante me gusto