• fullscreen
  • treecursion.pde
  • float curlx = 0; 
    float curly = 0; 
    float f = sqrt(2)/2.; 
    float deley = 10; 
    float growth = 0; 
    float growthTarget = 0; 
     
     
    void setup() 
    { 
      size(950,450,P2D); 
      //smooth(); 
      addMouseWheelListener(new java.awt.event.MouseWheelListener() {  
        public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {  
          mouseWheel(evt.getWheelRotation()); 
      }}); 
    } 
    void draw() 
    { 
      background(250); 
      stroke(0); 
      curlx += (radians(360./height*mouseX)-curlx)/deley; 
      curly += (radians(360./height*mouseY)-curly)/deley; 
      translate(width/2,height/3*2); 
      line(0,0,0,height/2); 
      branch(height/4.,17); 
      growth += (growthTarget/10-growth+1.)/deley; 
    } 
     
    void mouseWheel(int delta) 
    { 
      growthTarget += delta; 
    } 
     
    void branch(float len,int num) 
    { 
      len *= f; 
      num -= 1; 
      if((len > 1) && (num > 0)) 
      { 
        pushMatrix(); 
        rotate(curlx); 
        line(0,0,0,-len); 
        translate(0,-len); 
        branch(len,num); 
        popMatrix(); 
         
    //    pushMatrix(); 
    //    line(0,0,0,-len); 
    //    translate(0,-len); 
    //    branch(len); 
    //    popMatrix(); 
        len *= growth; 
        pushMatrix(); 
        rotate(curlx-curly); 
        line(0,0,0,-len); 
        translate(0,-len); 
        branch(len,num); 
        popMatrix(); 
        //len /= growth; 
      } 
    } 
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    James Noeckel

    Advanced Tree Generator

    Add to Faves Me Likey@! 127
    You must login/register to add this sketch to your favorites.

    Move the mouse around to affect brach tilt and spread. Scroll wheel changes size imbalance.

    bitcraft
    19 Apr 2010
    elegant code - awesome dynamics :-)
    Jean-no
    19 Apr 2010
    Very fast ! I think it would be better if you replace the mousewheel by arrow keys or something like that, because when I move the wheel, the page scrolls, it doesn't work very well within a browser.
    James Noeckel
    19 Apr 2010
    It doesn't do that with me. This sounds like the sort of thing Internet Explorer would do... try Firefox. I prefer to be able to control it with one hand by giving the mouse all the power.
    Claudio Gonzales
    19 Apr 2010
    Wow, that is simply amazing! I love how smoothly everything seems to flow, it's just as Martin said; elegant code and and awesome dynamics!
    Steven Kay
    20 Apr 2010
    the mousewheel behavior doesn't work in Chrome.. works a treat in FF though.

    in any case, a great sketch!
    James Noeckel
    20 Apr 2010
    Thanks. I sort of assumed that all browsers would isolate mousewheel behavior while one has a java applet selected as Firefox does. Chrome is still in development, though, so it might change.
    I don't use it though, only because it doesn't support Java under OSX yet. When they do, I'm switching again.
    Jean-no
    24 Apr 2010
    @James : I actualy use chrome
    Brian Sorahan
    7 May 2010
    What an interesting tree sketch! Love it.
    James, i used your sketch as background in my test with processingjs.

    http://amadeusfolego.heliohost.org/index.html
    Felix Woitzel
    14 Jun 2010
    whoa, it's fast and the dynamics rock! Well done!
    ArtMaggy
    3 Dec 2010
    Very interesting !
    Amazing sketch.
    How can i export the window of the tree generator to a PDF file?
    GNRTV DSGN
    20 Jan 2011
    How can i generate a PDF file? No Key?
    rupert russell
    15 Apr 2011
    I have added a link to this to my Fractal lesson plan http://www.rupert.id.au/fractals/lesson/lesson.php

    Thanks Rupert.
    Nom Bot
    24 Apr 2011
    one of the best here, intuitive and beautiful and well coded. just wow.
    rupert russell
    24 Apr 2011
    Hi I used this code to create these 2 T-Shirts http://www.redbubble.com/people/rupertrussell/t-shirts/7069976-tree-i & http://www.redbubble.com/people/rupertrussell/t-shirts/7076045-trees-ii

    Thanks for sharing this. It's lot's of fun.
    rupert russell
    24 Apr 2011
    Hi Siegfried & GNRTV DSGN to make a PDF you will have to download the code and use a library see: http://processing.org/reference/libraries/pdf/index.html to save tif is easer just add

    void mousePressed(){
    save("Tree");
    }

    to the bottom of the program and when you click the mouse it will save a file called tree.tif or you could go for something more fancy like

    void mousePressed(){

    save("Tree6_x" + str(x)+ "_y_"+ str(x)+"iter_"+str(itter));
    println("Tree6_x" + str(x)+ "_y_"+ str(x)+"_iter_"+str(itter));
    }

    Rupert
    jlm
    19 Sep 2011
    that great!!!!!awesome!!!
    It blew my mind, I discovered processing 3 days ago and and what I see here, just motivates me to learn more, thanx.
    kyley kirby
    8 Feb 2012
    It's not loading on my computer :(.
    this is soooo tight!
    Tim Pulver
    10 Jan 2013
    WOW! Love it!
    Panpan Deng
    16 Sep 2013
    WOW! GREAT JOB! I CAN PLAY IT FROEVER
    You need to login/register to comment.