In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

TreeDrawer

Get Adobe Flash player
by Robinftw 30 Mar 2012
    Embed
/**
 * Copyright Robinftw ( http://wonderfl.net/user/Robinftw )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/A0fU
 */

package {
    import flash.display.Sprite;
    public class TreeDrawer extends Sprite {
        public function TreeDrawer() {
            addChild(Debug.handle);
            
            // Creation of tree
            var stronk:Tak = new Tak();
            addChild(stronk);
            
            var tak1:Tak = new Tak;
            var tak2:Tak = new Tak;
            tak2.add(new Tak());
            tak2.add(new Tak());
            
            tak1.add(new Tak());
            tak1.add(tak2);
            tak1.add(new Tak());
            
            stronk.add(tak1);
            stronk.add(new Tak());
            
            
            
            stronk.draw();
        }
    }
}
import flash.utils.Proxy;
import flash.geom.Point;
import flash.text.*;

import flash.display.Sprite;
class Tak extends Sprite {
    public var color:uint; //Color of the tak.
    public var p:Tak; // Parent
    
    public var begin:Point = new Point();
    public var end:Point = new Point();
    
    private var takken:Array = new Array();
    public function Tak(p:Tak = null){
        setParent();
    }
    
    public function setParent(p:Tak = null):void{
        if(p == null){
            // Dit is de stronk
            this.begin = new Point(200,350);
            this.color = Color.BROWN;
            
            this.end.x = this.begin.x;
            this.end.y = this.begin.y - (Math.random()*80+10);
        }else{
            // Dit is een tak
           this.begin = p.end.clone();
           
           // Give random color
            this.color = (Math.random() > 0.5)? Color.RED : Color.BLUE;
            
            // Calculate where to grow to
            this.end.x = this.begin.x + Math.random()*75-35;
            this.end.y = this.begin.y - (Math.random()*80+10);
        }
        this.p = p;
        
        
        
        // Set children;
        for(var i:int = 0; i < takken.length; i++){
            takken[i].setParent(this);
        }
    }

    
    public function add(tak:Tak):void{
        tak.setParent(this);
        addChild(tak);
        takken.push(tak);
    }

    
    public function draw():void{
        // Self!
        this.graphics.lineStyle(3, color);
        this.graphics.moveTo(begin.x, begin.y);
        this.graphics.lineTo(end.x, end.y);
        
        // The children
        /*
        *
        *    Insert Iterator here.
        *
        */
        
        for(var i:int = 0; i < takken.length; i++){
            takken[i].draw();
        }

    }
}

class Color{
    public static const RED:uint = 0xFF0000;
    public static const BLUE:uint = 0x0000FF;
    public static const BROWN:uint = 0x994F28;
}


class Debug{
    private static var line:int = 0;
    public static var handle:Sprite = new Sprite();
    public static function trace(s:String):void{
        var text:TextField = new TextField();
        text.autoSize = TextFieldAutoSize.LEFT;
        text.text = s;
        handle.addChild(text);
        text.y = line++ * 12;
    }

}