xxxxxxxxxx
64
let drinkColor = ""; // Variable to store the color of the drink
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255);
fill(250); // Machine color
rect(40, 40, 320, 300, 20); // Outline of the machine
// Labels for the beverages
fill(0);
textSize(30);
textAlign(CENTER);
fill(139, 69, 19);
text("coffee", 100, 90);
fill(210, 180, 140);
text("tea", 210, 90);
fill(0);
text("milk", 320, 90);
// Drink color based on mouse position
if (mouseY < 300) {
// above the machine
if (mouseX > 50 && mouseX < 150) {
drinkColor = "darkbrown"; // coffee color
} else if (mouseX > 160 && mouseX < 260) {
drinkColor = "lightbrown"; // Tea color
} else if (mouseX > 270 && mouseX < 370) {
drinkColor = "white"; // milk color
} else {
drinkColor = ""; // no drink selected
}
} else {
drinkColor = ""; // reset drink color
}
// Draw the mug following the mouse position
let mugX = mouseX - 30; // center the mug under the mouse
let mugY = 300; // Y position for the mug
// Draw the mug rectangle
fill(255);
rect(mugX, mugY, 60, 30);
// fill inside the mug if a bev is selected
if (drinkColor == "darkbrown") {
fill(139, 69, 19); // Dark brown for coffee
} else if (drinkColor == "lightbrown") {
fill(210, 180, 140); // Light brown for tea
} else if (drinkColor == "white") {
fill(255); // White for milk
} else {
fill(255); // Default to white if no drink is selected
}
rect(mugX, mugY + 10, 60, 20); // Draw the liquid inside the mug
}