xxxxxxxxxx
70
let eggCooked = false; // Egg starts uncooked
let eggVisible = false; // Egg is hidden initially
let painting = false;
function setup() {
createCanvas(400, 400);
background(255);
// Draw bread initially
drawBread();
// Create the button to toggle between egg and omelette
let eggButton = createButton('Egg / Omelette');
eggButton.position(20, 20);
eggButton.mousePressed(function() {
eggVisible = true; // Make the egg/omelette visible
eggCooked = !eggCooked; // Toggle between cooked (omelette) and uncooked (egg)
drawBread(); // Redraw the bread to keep it visible
});
// Create the button to enable painting on the bread
let breadButton = createButton('Paint Bread');
breadButton.position(150, 20);
breadButton.mousePressed(function() {
painting = true; // Enable painting mode
});
}
function draw() {
// Allow painting on the bread if the painting mode is active and the mouse is pressed
if (painting && mouseIsPressed) {
if (mouseX > 120 && mouseX < 280 && mouseY > 180 && mouseY < 300) {
fill(255, 0, 0, 150); // Red color for painting
ellipse(mouseX, mouseY, 20, 20); // Draw red circles
}
}
// Draw the egg or omelette based on the current state
if (eggVisible) {
if (eggCooked) {
drawOmelette(); // If egg is cooked, draw an omelette
} else {
drawEgg(); // If egg is not cooked, draw an egg
}
}
}
function drawBread() {
fill(200, 160, 100);
rect(120, 180, 160, 120, 20); // Draw bread with rounded corners
fill(224, 185, 137);
rect(130, 190, 140, 100, 15); // Lighter color for inner bread
}
function drawEgg() {
// Draw egg white
fill(255); // Egg white color
ellipse(300, 300, 100, 70); // Egg white shape
// Draw egg yolk in the center
fill(255, 200, 0); // Egg yolk color
ellipse(300, 300, 40, 40); // Egg yolk shape
}
function drawOmelette() {
// Draw omelette
fill(255, 204, 100); // Omelette color
ellipse(300, 300, 100, 70); // Omelette shape
}