Interface 7
Sun Jan 07 2024 18:28:44 GMT+0000 (Coordinated Universal Time)
Saved by
@马丽
boolean isMousePressed = false;
void setup() {
size(400, 400); // Set canvas size
background(220); // Set background color
}
void draw() {
// This function is intentionally left empty
}
void mousePressed() {
// Change the background color when the mouse is pressed
background(random(255), random(255), random(255));
// Set the mouse pressed state to true
isMousePressed = true;
// Show text "Clicked" at the center of the canvas
showText("Clicked");
}
void mouseReleased() {
// If the mouse was pressed, change the background color and show "Released"
if (isMousePressed) {
background(random(255), random(255), random(255));
showText("Released");
}
// Set the mouse pressed state to false
isMousePressed = false;
}
void showText(String message) {
fill(0); // Set text color to black
textSize(20); // Set text size
textAlign(CENTER, CENTER); // Center align the text
text(message, width / 2, height / 2);
}
content_copyCOPY
Comments