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 />

516<br />

Figure 11-14. Weights on Springs sketch<br />

Even the simplest wavy/springy behavior can be evocative <strong>and</strong> even humorous. I’ve created<br />

two final spring examples that illustrate this. The first sketch is of a simple undulating<br />

sine wave that moves across the display window. When I showed the initial state of this<br />

sketch to my six-year-old son, he immediately saw its connection to the way water moves,<br />

so I added an additional playful element. This example, entitled Beach Ball, is a bit long, so<br />

I’ve provided it as a download, which you can find in the Download section of the friends<br />

of ED website (www.friendsofed.com/downloads.html).<br />

Soft-body dynamics<br />

The second example is of a springy polygon that combines both approaches to springing<br />

we’ve looked at this chapter. This sketch is loosely inspired by the brilliant Java work<br />

Sodaplay (www.sodaplay.com/constructor/index.htm), created by Ed Burton <strong>and</strong> team at<br />

Soda <strong>Creative</strong> (http://soda.co.uk/). The example illustrates (very) simple soft-body<br />

dynamics. In rigid-body dynamics, objects collide <strong>and</strong> interact, but the objects themselves<br />

don’t deform; think of a block of wood falling down the stairs. In soft-body dynamics, the<br />

objects actually deform; think of a water balloon falling down the stairs (but not exploding).<br />

People are often fascinated by these types of simulations (I know I am), <strong>and</strong> in many<br />

ways they represent the ultimate illusion. Since we are more or less squishy, soft-bodied<br />

organisms ourselves, these types of soft-body physics simulations represent a logical<br />

extension of earlier creative attempts at human depiction—from cave paintings, to terra<br />

cotta figures, to self-portraiture, to Shrek’s bouncing belly. Following is the code for<br />

Hybrid Springy Dude: A Polygon with Attitude (shown in Figure 11-15):<br />

/* Hybrid Springy Dude:<br />

A Polygon with Attitude */<br />

// center point<br />

float centerX = 0, centerY = 0;<br />

float radius = 60, rotAngle = -90;<br />

float accelX, accelY;<br />

float springing = .0085, damping = .98;

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

Saved successfully!

Ooh no, something went wrong!