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.

lower particle speed<br />

ySpeed[i]*=gravity;<br />

// keep particle from sliding out of window<br />

y[i]=height;<br />

}<br />

This expression slowly reduces the particle’s velocity (ySpeed) until it is very near zero.<br />

However, because ySpeed will actually never reach zero, I am forced to add the final<br />

assignment, y[i]=height, which keeps the particles from slowly creeping off the bottom<br />

of the screen. I’ll revisit this issue again in more detail in Chapter 11. As always, play with<br />

the code. If you comment out this last assignment, you should notice the output is a little<br />

lower in relation to the display window.<br />

In the next example (shown in Figure 7-11), I pushed this particle effect a little further,<br />

utilizing a new material property, more r<strong>and</strong>omization, <strong>and</strong> additional display edge detection.<br />

There’s nothing really new in the example, but it should reveal some more of the<br />

interesting effects you can get coding curved motion. This example can take a long time to<br />

render—up to 30 seconds. Decreasing the strokeWtMin <strong>and</strong> strokeWtMax argument values<br />

will speed things up. However, on some systems, too small a value may make the curves<br />

undetectable.<br />

/*<br />

Curves III<br />

Ira Greenberg, December 4, 2005<br />

// this takes some time to render<br />

*/<br />

// changeable variables<br />

int particles = 125;<br />

int timeLimit = 2000;<br />

float particleSpan = 2;<br />

float accelMin = .005;<br />

float accelMax = .2;<br />

float strokeWtMin = 1.25;<br />

float strokeWtMax = 1.6;<br />

float materialMin = .25;<br />

float materialMax = .99;<br />

float gravity = .9;<br />

// not meant to be changed<br />

int timer;<br />

float[]x = new float[particles];<br />

float[]y = new float[particles];<br />

float[]xSpeed = new float[particles];<br />

float[]ySpeed = new float[particles];<br />

float[]accel = new float[particles];<br />

float[]material = new float[particles];<br />

float[]strokeWts = new float[particles];<br />

CURVES<br />

253<br />

7

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

Saved successfully!

Ooh no, something went wrong!