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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The overall movement was good, but the tree seemed too stiff, so I wrote a little redrawing<br />

function that added some waviness to the main trunk, <strong>and</strong> I set this up as a r<strong>and</strong>om<br />

value. Using r<strong>and</strong>omness is really helpful for generating organic-esque type effects. One of<br />

the potential pitfalls of using code as a creative medium is its inherent precision, since it’s<br />

ultimately based on math. In the real world, “stuff” (friction, gravity, our ineptitude, etc.)<br />

intervenes between intention <strong>and</strong> implementation—the happy accidents. Adding r<strong>and</strong>omness<br />

is one (easy) way to introduce some happy chaos into an otherwise highly predictable<br />

process (see Figure 2-6). Normally when I use r<strong>and</strong>om values, I set a base number that I<br />

add to the r<strong>and</strong>om part. For example, if I were creating a r<strong>and</strong>om number of branches,<br />

<strong>and</strong> I used a r<strong>and</strong>om function, such as r<strong>and</strong>om(12), I would get a number returned<br />

between 0 <strong>and</strong> 12. However, if I needed a minimum of two branches, I would change the<br />

expression to “2+r<strong>and</strong>om(10)”—this way, I would get a r<strong>and</strong>om number between 2 <strong>and</strong> 12.<br />

<strong>Processing</strong> has a h<strong>and</strong>y r<strong>and</strong>om function that allows you to pass two arguments, as in<br />

r<strong>and</strong>om(2, 12), which does the same thing.<br />

Figure 2-6. Waviness added to the main trunk<br />

Things were beginning to look pretty good, but I still needed to deal with those darn<br />

leaves. Then, a really happy coding accident happened. As I began to play with the code,<br />

setting weird numbers in the functions, I found a way of generating leaves by really upping<br />

the number of iterations <strong>and</strong> using a couple of conditional statements (if <strong>and</strong> else) that<br />

would at specific times in the branch-creation cycle decrement or increment certain values.<br />

Then I added some color the same way, <strong>and</strong> finally used a similar wavy function for<br />

each branch, like I used on the trunk. Figure 2-7 shows a couple of finished trees.<br />

CREATIVE CODING<br />

49<br />

2

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

Saved successfully!

Ooh no, something went wrong!