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.

386 <strong>Learning</strong> <strong>Processing</strong><br />

Exercise 20-2: Rewrite the Doorbell class <strong>to</strong> include a reference <strong>to</strong> the Sonia sample. Th is<br />

will allow you <strong>to</strong> easily make multiple Doorbell objects that each play a diff erent sound.<br />

Here is some code <strong>to</strong> get you started.<br />

// A Class <strong>to</strong> describe a " doorbell " (really a but<strong>to</strong>n)<br />

class Doorbell {<br />

// Location and size<br />

float x;<br />

float y;<br />

float r;<br />

// A sample object (for a sound)<br />

_________ ____________;<br />

// Create the doorbell<br />

Doorbell (float x_, float y_, float r_, _______ filename) {<br />

}<br />

}<br />

x = x_;<br />

y = y_;<br />

r = r_;<br />

_________ = new _________(_____________);<br />

void ring() {<br />

}<br />

____________________;<br />

boolean contains(float mx, float my) {<br />

}<br />

// same as original<br />

void display(float mx, float my) {<br />

}<br />

// same as original<br />

If you run the Doorbell example and click on the doorbell many times in rapid succession, you will notice<br />

that the sound restarts every time you click. It is not given a chance <strong>to</strong> fi rst fi nish playing. While this<br />

is not much of an issue for this straightforward example, s<strong>to</strong>pping a sound from restarting can be very<br />

important in other, more complex, sound sketches. Th e simplest way <strong>to</strong> achieve such a result is <strong>to</strong> always

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

Saved successfully!

Ooh no, something went wrong!