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.

draw orb<br />

noStroke();<br />

fill(200);<br />

ellipse(orb.x, orb.y, orb.r*2, orb.r*2);<br />

// collision detection<br />

checkWallCollision();<br />

checkGroundCollision();<br />

}<br />

Figure 11-21. Non-orthogonal Collision Based on Rotated Coordinates<br />

sketch<br />

Each time you run the sketch, a r<strong>and</strong>omly sloped ground plane is created. I didn’t bother<br />

to actually draw the ground plane normal as I did in the earlier example, but notice how<br />

the angle of incidence of the orb <strong>and</strong> the angle of reflection are symmetrical based on<br />

where the normal would be perpendicular to the ground.<br />

Stage 2: Segmented ground plane<br />

In the next stage of the sketch, shown in Figure 11-22, I’ll add a segmented ground plane,<br />

allowing the orb to bounce more erratically from numerous collisions on different angled<br />

surfaces. The three classes <strong>and</strong> the checkWallCollision() function will remain<br />

unchanged. Some minor modifications will need to be made to the main tab <strong>and</strong> the<br />

checkGroundCollision() function. The changes to the existing code are in bold. Here’s<br />

the code for the main sketch tab:<br />

MOTION<br />

541<br />

11

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

Saved successfully!

Ooh no, something went wrong!