Files
sunny9898/task8/wk9/wk9_example_1/wk9_example_1.pde
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

38 lines
663 B
Plaintext

// Based on Example 20-2: Doorbell with Sonia in Learning Processing
import processing.sound.*;
SoundFile dingdong;
int x, y, d;
void setup() {
size(200, 200);
// Load the sound file
dingdong = new SoundFile(this, "doorbell.mp3");
x = width/2;
y = height/2;
d = 64;
strokeWeight(4);
}
void draw() {
background(255);
if (checkInCircle())
fill(100);
else
fill(175);
ellipse(x, y, d, d);
}
void mousePressed() {
// If the user clicks on the doorbell, play the sound!
if (checkInCircle()) {
dingdong.play();
}
}
boolean checkInCircle() {
if (dist(mouseX, mouseY, x, y) <= d/2)
return true;
else
return false;
}