• fullscreen
  • Tree.pde
  • treeSketch.pde
  • class Tree {
      float x, y;
      float h;
      float steps;
      
      Tree() {
        x = 0;
        y = 0;
        h = 0;
        steps = 0;
      }
      
      Tree(int x_, int y_, int h_, int s_) {
        x = x_;
        y = y_;
        h = map(h_, 0, height, 0, 160);
        steps = s_;
      }
      
      void render() {
        stroke(32);
        branch(x, y, -HALF_PI, h);
      }
      
      void branch(float x_, float y_, float a_, float s_) {
        strokeWeight(s_/16);
        float a = random(-PI/16, PI/16)+a_;
        float nx = cos(a)*s_+x_;
        float ny = sin(a)*s_+y_;
        stroke(32, 16*s_);
        line(x_, y_, nx, ny);
        if (s_>10) {
          branch(nx, ny, a_-random(PI/4), s_*random(0.6, 0.8));
          branch(nx, ny, a_, s_*random(0.6, 0.8));
          branch(nx, ny, a_+random(PI/4), s_*random(0.6, 0.8));
        } else {
          float w = random(155, 255);
          stroke(255, w, w, random(32, 192));
          strokeWeight(random(0, 8));
          point(nx+random(-2, 2), ny+random(-2, 2));
        }
      }
    }
    
    Tree tree = new Tree();
    
    void setup() {
      size(512, 320);
      colorMode(RGB, 255);
      background(192);
      smooth();
    }
    
    void draw() {
    }
    
    void keyReleased() {
      background(192);
    }
    
    void mouseReleased() {
      tree = new Tree(mouseX, height, height-mouseY, 5);
      tree.render();
    }
    
    
      
    

    code

    tweaks (1)

    about this sketch

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

    license

    advertisement

    Mark Brand
    Yuriy Flyud
    1 Jun 2009
    Wow, it's beautiful, realy very nice)))
    Kyoko Masuda
    12 Jun 2009
    Beautiful. I love your pick for the color of the flowers as well.
    Guigui plus+
    15 Jun 2009
    A classical work, very well done. I like your code. Often short & simple. 8^)
    belen hernandez
    17 Jun 2009
    love it
    :)
    Cheng Siu Yee
    1 Sep 2009
    Very beautiful!
    Chris Enyeart
    6 Jan 2010
    Nice work. I wanted to make it less straight more natural looking so I changed a couple of lines:

    old code :
    line(x_, y_, nx, ny);

    new:
    int ay = (int)(y_+ ny)/2;
    smooth();
    noFill();
    bezier(x_, y_, x_, ay, nx, ay, nx, ny);
    You need to login/register to comment.