04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Obviously, there are a lot of things I could still do with the tree code, but hopefully one of<br />

you will eventually take the code <strong>and</strong> improve upon it. I hope I was able to illustrate in this<br />

example how you can play with the code <strong>and</strong> even find stuff in the process of coding. Yes,<br />

there is some thinking involved, but there is also a lot of play <strong>and</strong> discovery. I’ve included<br />

the entire tree program following, with code comments for your hacking pleasure. If you<br />

want to try running this, launch <strong>Processing</strong> <strong>and</strong> type (or paste) the code into the<br />

<strong>Processing</strong> text editor.<br />

/*<br />

algorithmic tree sketch<br />

Ira greenberg, August, 2005<br />

*/<br />

/* import H<strong>and</strong>y Java class with<br />

public x <strong>and</strong> y float props */<br />

import java.awt.geom.Point2D;<br />

// declare/define global variables<br />

int counter;<br />

int counter2;<br />

float xg = 58;<br />

float yg = 46;<br />

int trunkSegments = int(r<strong>and</strong>om(7))+5;<br />

int nodeLimit = 20000;<br />

Point2D.Float[]pts = new Point2D.Float[nodeLimit];<br />

int branchLimit = 620;<br />

float trunkLength = int(r<strong>and</strong>om(50))+130;<br />

float[]lean2 = new float[trunkSegments+1];<br />

float radius = 26;<br />

// initialize sketch<br />

void setup(){<br />

size(900, 600);<br />

background(255);<br />

stroke(30, 10, 5);<br />

// create tree turnk<br />

trunk();<br />

}<br />

void trunk(){<br />

//draw trunk<br />

for (int i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!