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.

To avoid unintentional clumping of the balls at collision, I borrowed a nice hack from<br />

Keith’s example, which essentially moves the balls a little away from each other upon collision<br />

detection so that clumping is avoided. It’s not a perfect fix, but it sure is nice <strong>and</strong><br />

simple.<br />

We’re almost home now. The last steps left are to rotate the rotated ball position values<br />

<strong>and</strong> velocities back to the original rotation at collision <strong>and</strong> to update the balls’ positions to<br />

the screen (remember that I treated the rotation locally with regard to the vector between<br />

the balls, rotating b[1] around b[0]). Updating the balls’ screen positions just entails<br />

adding the final ball positions (bFinal) to b[0].<br />

That’s it! Definitely take some time playing with this sketch, plugging in different values for<br />

the balls’ radii (which, again, control mass) <strong>and</strong> the initial velocities, both defined in the<br />

sketch’s main tab.<br />

There is so much more that could be done with this sketch, <strong>and</strong> collisions in general,<br />

including the addition of more balls. Likewise, orb-orb collisions could also be introduced<br />

to the Asteroid Shower example. That being said, I think this chapter’s gone on long<br />

enough.<br />

Summary<br />

This chapter began with a brief overview of some of the technical issues involved in computer-based<br />

animation, including the concept of threads <strong>and</strong> the use of timeline-based<br />

keyframe models commonly found in high-end animation applications. Comparing Java<br />

<strong>and</strong> <strong>Processing</strong> animation code side by side, I showed how <strong>Processing</strong>’s draw() structure<br />

encapsulates much of the low-level (<strong>and</strong> annoying) aspects of programmatic animation.<br />

Beginning with a simple moving ball <strong>and</strong> eventually adding simple physics, you explored<br />

easing, springing, <strong>and</strong> the concept of soft-body dynamics. <strong>Coding</strong> collisions, with some<br />

help from code guru Keith Peters, I introduced different approaches for h<strong>and</strong>ling both<br />

orthogonal <strong>and</strong> non-orthogonal 1D collisions, including ways to work with multiple surfaces<br />

<strong>and</strong> objects. Finally, I introduced an advanced 2D collision example that included<br />

conservation of momentum calculations.<br />

In the next chapter, we’ll add interactivity into the mix, allowing the user to interact with<br />

your sketches. We’ll also discuss the possibilities of generating applications <strong>and</strong> graphical<br />

user interfaces (GUIs) in <strong>Processing</strong>.<br />

MOTION<br />

561<br />

11

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

Saved successfully!

Ooh no, something went wrong!