06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

396 <strong>Learning</strong> <strong>Processing</strong><br />

// Draw lines at the threshold levels<br />

stroke(0);<br />

line(0,height-clapLevel*height/2,19,height-clapLevel*height/2 );<br />

line(0,height-threshold*height/2,19,height-threshold*height/2 );<br />

}<br />

// Close the sound engine<br />

public void s<strong>to</strong>p() {<br />

Sonia.s<strong>to</strong>p();<br />

super.s<strong>to</strong>p();<br />

}<br />

Exercise 20-6: Trigger the event from Example 20-7 after a sequence of two claps. Here is<br />

some code <strong>to</strong> get you started that assumes the existence of a variable named “ clapCount ” .<br />

if (vol > c lapLevel & & !clapping) {<br />

clapCount___;<br />

if (_______________) {<br />

}<br />

________________;<br />

________________;<br />

________________;<br />

_________________;<br />

} else if (clapping & & vol < 0.5) {<br />

}<br />

clapping = false;<br />

Exercise 20-7: Create a simple game that is controlled with volume. Suggestion: First make<br />

the game work with the mouse, then replace the mouse with live input. Some examples are<br />

Pong, where the paddle’s position is tied <strong>to</strong> volume, or Duck Hunt, where a bullet is shot<br />

whenever the user claps.

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

Saved successfully!

Ooh no, something went wrong!