• fullscreen
  • sketch68716.pde
  • void setup() {
      size(800, 600, P2D);
    }
    
    int maxbranch =8;
    float ang = 0;
    float ang2 = 0;
    float distance;
    
    PFont font = createFont("Arial", 20);
    
    void draw() {
      background(80);
      //stroke(0);
      ang2 = map(mouseX, 0, width, 0, 2*PI);
      ang = map(mouseY, 0, 600, -PI, 0);
      distance = 160;
      pushMatrix();
        translate(400,550);
        branch(0);
      popMatrix();
      infoText();
    }
    
    void branch(float incnt){
      float cnt = incnt;
      cnt++;
      stroke(0,255/(cnt/2));
      fill(255,255,0,255/(cnt/2));
      quad(-15/cnt,0,15/cnt,0,15/(cnt+1),-distance/(cnt),-15/(cnt+1),-distance/(cnt));
      ellipseMode(CENTER);
      if (cnt>1) ellipse(0,0,30/cnt,30/cnt);
      if (cnt < maxbranch){
        pushMatrix();
          translate(0,-distance/(cnt));
          rotate(ang+ang2);
          branch(cnt);
        popMatrix();
        pushMatrix();
          translate(0,-distance/(cnt));
          rotate(-ang+ang2);
          branch(cnt);
        popMatrix();
      }
    }
    
    void infoText(){
      stroke(0);
      fill(0);
      String txt = "PLAY THE TREE \n" +
                   "Move mouse around and see what happens \n" +
                   "LMB = increase branches \n" + "RMB = decrease branches \n" +
                   "Number of branches = " + (maxbranch);
      text(txt,20,40);
    }
    
    void mouseReleased(){
      if (mouseButton == LEFT){
        if (maxbranch < 12) maxbranch++;
      }
      if (mouseButton == RIGHT){
        if (maxbranch > 1) maxbranch--;
      }
    }

    code

    tweaks (0)

    about this sketch

    This sketch is running in HTML5 using Processingjs.

    license

    advertisement

    Report Sketch

    Report for inappropriate content

    Please provide details if possible:

    Your have successfully reported the sketch. Thank you very much for helping to keep OpenProcessing clean and tidy :)

    Make a Copyright Infringement claim

    Kostas Sfikas
    Liam Farley
    12 Sep 2012
    This is really good.
    Kostas Sfikas
    14 Sep 2012
    thanks!

    I could add some comments in the code, although it is quite simple.
    Kostas Sfikas
    14 Sep 2012
    There are many examples of recursive trees in the openProcessing collection. Mine have come up after this discussion: https://forum.processing.org/topic/3d-tree-growth-simulator
    I love it! and used it to make this gif http://wavegrower.tumblr.com/post/117361791800/fractal-wave-inspired-by-this-excellent-sketch-by. Many thanks for the inspiration, and congrats for the good job!
    Kostas Sfikas
    25 Apr 2015
    Hey, thanks! nice job on the curves, btw..
    I suppose it's some kind of sinusoidal function on a series of circles?*
    Or did you make the curves using splines?

    *if that's the case, it must have taken quite some time for each frame, right?

    you may check this out as well
    https://www.youtube.com/user/konsfik/playlists?sort=dd&view=50&shelf_id=21
    yes, sine functions on multiple discs through the Ondulator class, as usual in all my works (check my portfolio)
    true that it was playing very very slow :)
    You need to login/register to comment.