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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

46<br />

Figure 2-2. Initial schematic sketch of tree branching structure.<br />

The numbers represent the algorithmic branching order.<br />

The drawing is a basic symmetrical tree structure in a purely schematic form. Between<br />

each branch is a node. I added some numbers for the nodes to think a little how the computer<br />

would sequentially draw the structure. So I was now ready for an algorithm that<br />

would help me write code to generate the tree form. Again, the tree trunk was just going<br />

to be a line, so I figured I’d come back to it. Here’s the branching algorithm:<br />

1. Draw two or more opposing diagonal branches from the top of the trunk.<br />

2. At the ends of these branches, continue adding two or more opposing diagonal,<br />

slightly thinner branches.<br />

3. Go back to step two until a specific limit is reached.<br />

The algorithm seemed simple enough, <strong>and</strong> I noticed that it could possibly loop back on<br />

itself—or even call itself. We call such an approach in programming recursion, where a<br />

function calls itself. Recursion is a somewhat advanced concept, even though it is not that<br />

difficult to implement. Recursion will lead to an infinite loop (a bad thing) unless some<br />

explicit limit is set. For example, I could tell the program to run until one of the branches<br />

touched the top of the frame, or until there are 700 branches on the tree, <strong>and</strong> so on.<br />

After a couple of well-placed slaps to my head, I finally got the basic branching code written<br />

(please note that this code fragment will not run in <strong>Processing</strong> yet):<br />

void branch(Point2D.Float[] pts){<br />

int stemCount=2;<br />

if (counter2

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

Saved successfully!

Ooh no, something went wrong!