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

494<br />

Figure 11-6. Acceleration with Gravity sketch<br />

I reused the fade technique from the last example to help visualize the rectangle’s curved<br />

motion. This sketch is structured pretty similarly to the earlier ones we looked at, with the<br />

addition of accelerated motion on the y-axis. x continues to be incremented by xSpeed<br />

(providing a constant rate of change), but I’ve added an extra gravity variable for the y<br />

motion. Prior to incrementing y by ySpeed, I incremented ySpeed by gravity. This extra<br />

assignment created accelerated motion, as the rate of change of y was no longer constant.<br />

To illustrate why this double incrementation works, run the following sketch. The output,<br />

shown in Figure 11-7, shows the actual values for x <strong>and</strong> y over five iterations:<br />

// Acceleration Calculations<br />

float x = 0, x2 = 0, y = 0, y2 = 0;<br />

float xSpeed = 3.0, ySpeed = .0;<br />

float gravity = .5;<br />

void setup(){<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!