xxxxxxxxxx
143
let fortuneCookie;
let openedFortuneCookie;
let isOpened = false;
let currentFortune;
let fortunes = [
"Your coding skills will bring you great success!",
"A surprising opportunity will come your way soon.",
"Your creativity will lead you to new heights.",
"An exciting journey awaits you in the near future.",
"Your hard work will pay off in unexpected ways.",
"A new friendship will bring joy to your life.",
"Your kindness will return to you tenfold.",
"An important decision will bring positive change.",
"Your curiosity will lead you to great discoveries.",
"Success is in your future if you persevere.",
];
function setup() {
createCanvas(800, 600);
fortuneCookie = createGraphics(400, 300);
openedFortuneCookie = createGraphics(400, 300);
drawFortuneCookie(fortuneCookie);
currentFortune = random(fortunes);
drawOpenedFortuneCookie(openedFortuneCookie, currentFortune);
}
function draw() {
background(240, 230, 220); // Light beige wall color
// Floor
fill(160, 82, 45);
rect(0, 500, width, 100);
// Tables
drawTable(200, 450);
drawTable(600, 450);
// Wall decorations
drawWallDecoration(100, 100);
drawWallDecoration(700, 100);
// Lanterns
drawLantern(300, 100);
drawLantern(500, 100);
// Fortune Cookie
if (isOpened) {
image(openedFortuneCookie, 100, 150);
} else {
image(fortuneCookie, 100, 150);
}
}
function mousePressed() {
isOpened = !isOpened;
if (isOpened) {
currentFortune = random(fortunes);
drawOpenedFortuneCookie(openedFortuneCookie, currentFortune);
}
}
function drawTable(x, y) {
fill(139, 69, 19); // Dark wood color
rect(x - 50, y, 100, 10); // Table top
rect(x - 40, y + 10, 10, 40); // Left leg
rect(x + 30, y + 10, 10, 40); // Right leg
}
function drawWallDecoration(x, y) {
fill(255, 0, 0); // Red color
rect(x - 30, y, 60, 90);
fill(255, 215, 0); // Gold color
textSize(40);
textAlign(CENTER, CENTER);
text("福", x, y + 45);
}
function drawLantern(x, y) {
fill(255, 0, 0); // Red color
ellipse(x, y + 40, 60, 80);
fill(255, 215, 0); // Gold color
rect(x - 5, y, 10, 20);
ellipse(x, y + 80, 20, 10);
}
function drawFortuneCookie(g) {
g.background(240, 230, 220, 0);
// Cookie shape
g.fill(255, 235, 180);
g.noStroke();
g.beginShape();
g.vertex(200, 150);
g.bezierVertex(250, 100, 350, 100, 400, 150);
g.bezierVertex(380, 200, 220, 200, 200, 150);
g.endShape(CLOSE);
// Shadow
g.fill(0, 0, 0, 30);
g.ellipse(300, 220, 180, 40);
// Fold line
g.stroke(200, 180, 140);
g.strokeWeight(2);
g.line(200, 150, 400, 150);
// Fortune paper
g.fill(255);
g.noStroke();
g.rect(290, 133, 60, 15);
g.rect(320, 118, 30, 15);
}
function drawOpenedFortuneCookie(g, fortune) {
g.background(240, 230, 220, 0);
// Bottom half of cookie
g.fill(255, 235, 180);
g.noStroke();
g.beginShape();
g.vertex(150, 200);
g.bezierVertex(200, 250, 300, 250, 350, 200);
g.bezierVertex(330, 180, 170, 180, 150, 200);
g.endShape(CLOSE);
// Top half of cookie
g.beginShape();
g.vertex(200, 100);
g.bezierVertex(250, 50, 350, 50, 400, 100);
g.bezierVertex(380, 120, 220, 120, 200, 100);
g.endShape(CLOSE);
// Fortune paper
g.fill(255);
g.rect(180, 150, 240, 60);
// Fortune text
g.fill(0);
g.textSize(14);
g.textAlign(CENTER, CENTER);
g.text(fortune, 180, 150, 220, 50);
}