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.

Before moving on, try experimenting with the values for xSpeed, gravity, damping, <strong>and</strong><br />

friction. You should easily be able to simulate different gravities (as you’d encounter on<br />

different planets), as well as different materials for the rectangle <strong>and</strong> ground surface. For<br />

example, to simulate a lead block being dropped on the moon <strong>and</strong> l<strong>and</strong>ing on a rough surface,<br />

you could try the following settings:<br />

speedX = 1;<br />

gravity = .02;<br />

damping = .85;<br />

friction = .6;<br />

To simulate a lacrosse ball l<strong>and</strong>ing on Jupiter on a super smooth, slick surface, try the<br />

following:<br />

speedX = 5;<br />

gravity = .98;<br />

damping = .75;<br />

friction = .99;<br />

Figure 11-8 shows these two scenarios side by side, without a background() call in draw().<br />

Figure 11-8. Simple Motion Physics I sketch<br />

Converting this sketch of a single bouncing rectangle with naturalesque physics to many<br />

rectangles is as easy as creating arrays for each of the individual variables <strong>and</strong> adding for<br />

loops within the setup() <strong>and</strong> draw() functions. That being said, all the array syntax can<br />

look a little intimidating.<br />

In addition to the arrays, I added three variables (shapeCount, birthRate, <strong>and</strong> sprayWidth)<br />

to control how the rectangles are born. Without controlling the birthrate, all the rectangles<br />

would be born at the same time, creating a much less interesting effect than the spray<br />

effect we get in the sketch. Also, by using the sprayWidth variable in setting the xSpeed[]<br />

values, I can control the width of the spray. Output from the sketch is shown in Figure 11-9.<br />

MOTION<br />

497<br />

11

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

Saved successfully!

Ooh no, something went wrong!