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.

void mousePressed() {<br />

// If the user clicks on the doorbell, play the sound!<br />

if (doorbell.contains(mouseX,mouseY)) {<br />

dingdong.play();<br />

}<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 />

// 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 />

// Create the doorbell<br />

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

x = x_;<br />

y = y_;<br />

r = r_;<br />

}<br />

// Is a point inside the doorbell (used for mouse rollover, etc.)<br />

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

if (dist(mx,my,x,y) < r) {<br />

return true;<br />

} else {<br />

return false;<br />

}<br />

}<br />

// Show the doorbell (hardcoded colors, could be improved)<br />

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

if (contains(mx,my)) {<br />

fill(100);<br />

} else {<br />

fill(175);<br />

}<br />

stroke(0);<br />

ellipse(x,y,r,r);<br />

}<br />

}<br />

Sound 385

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

Saved successfully!

Ooh no, something went wrong!