top of page

A graphic Recursion

  • Karla G
  • 28 mar 2015
  • 1 Min. de lectura

Here we have a recursive tree made by Daniel Shiffman, that changes its brenchs depending on the mouse position:

The different designs that are printed:

Captura de pantalla 2015-03-27 a las 22.12.49.png

Captura de pantalla 2015-03-27 a las 22.12.39.png

Captura de pantalla 2015-03-27 a las 22.12.23.png

The code:

float theta;

void setup() {

size(640, 360);

}

void draw() {

background(0);

frameRate(30);

stroke(255);

// Let's pick an angle 0 to 90 degrees based on the mouse position

float a = (mouseX / (float) width) * 90f;

// Convert it to radians

theta = radians(a);

// Start the tree from the bottom of the screen

translate(width/2,height);

// Draw a line 120 pixels

line(0,0,0,-120);

// Move to the end of that line

translate(0,-120);

// Start the recursive branching!

branch(120);

}

void branch(float h) {

// Each branch will be 2/3rds the size of the previous one

h *= 0.66;

// All recursive functions must have an exit condition!!!!

// Here, ours is when the length of the branch is 2 pixels or less

if (h > 2) {

pushMatrix(); // Save the current state of transformation (i.e. where are we now)

rotate(theta); // Rotate by theta

line(0, 0, 0, -h); // Draw the branch

translate(0, -h); // Move to the end of the branch

branch(h); // Ok, now call myself to draw two new branches!!

popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state

// Repeat the same thing, only branch off to the "left" this time!

pushMatrix();

rotate(-theta);

line(0, 0, 0, -h);

translate(0, -h);

branch(h);

popMatrix();

}

}

References:

Processing. (2001). Processing. 24 Marzo 2015, de Processing.org Sitio web: https://processing.org/

 
 
 

Comentários


 THE ARTIFACT MANIFAST: 

 

This is a great space to write long text about your company and your services. You can use this space to go into a little more detail about your company. Talk about your team and what services you provide. Tell your visitors the story of how you came up with the idea for your business and what makes you different from your competitors. Make your company stand out and show your visitors who you are. Tip: Add your own image by double clicking the image and clicking Change Image.

 UPCOMING EVENTS: 

 

10/31/23:  Scandinavian Art Show

 

11/6/23:  Video Art Around The World

 

11/29/23:  Lecture: History of Art

 

12/1/23:  Installations 2023 Indie Film Festival

 FOLLOW THE ARTIFACT: 
  • Facebook B&W
  • Twitter B&W
  • Instagram B&W
 RECENT POSTS: 
 SEARCH BY TAGS: 

© 2023 by Karla Lugo. Proudly created with Wix.com

bottom of page