xxxxxxxxxx
256
let flower_position = []; // to store positions of flowers
let flower_count = 0; // tto count the no. of flowers created
let celeb_start = false; // to track if celebration has started
let confetti = []; // to store confetti positions
let fall_flowers = []; // to store falling flowers positions
function setup() {
createCanvas(330, 350);
background(255, 200, 200); // initial background color
// the ground
fill(34, 139, 34);
noStroke();
rect(0, height - 50, width, 50); // rectangle at the bottom of the canvas
}
function draw() {
background(255, 200, 200); // redrawing the background each frame to make the falling of items smooth
// the ground
fill(34, 139, 34);
noStroke();
rect(0, height - 50, width, 50); // rectangle at the bottom of the canvas
// drawing the hair (top and sides)
noStroke();
fill(79, 49, 30); // Dark brown hair color
// top of the head - arc creates a rounded hairline
arc(150, 130, 170, 170, PI, TWO_PI);
// hair on the sides
rect(65, 130, 170, 195);
// hair details using lines
stroke(101, 67, 33);
strokeWeight(2);
line(150, 46, 150, 66); // mid-parting of hair
// lines on the side of the hair for detailss
strokeWeight(2);
line(75, 180, 75, 320);
line(95, 180, 95, 320);
line(115, 180, 115, 320);
line(185, 180, 185, 320);
line(205, 180, 205, 320);
line(225, 180, 225, 320);
// neck
noStroke();
fill(229, 181, 161); // Skin color for the neck
rect(123, 220, 55, 60); // Rectangular neck shape
// head shape
fill(232, 190, 172); // Skin tone for face
ellipse(150, 150, 145, 165); // Face shape
// hair bangs
stroke(79, 49, 30);
strokeWeight(3);
for (let i = 0; i < 9; i++) {
line(150, 65, 150 + (i * 10), 110);
}
line(150, 65, 225, 100);
line(150, 65, 220, 90);
for (let i = 0; i < 9; i++) {
line(150, 65, 150 - (i * 10), 110);
}
line(150, 65, 75, 100);
line(150, 65, 80, 90);
// eyes follow the cursor
let eyeX1 = 115 + (mouseX - 115) * 0.1; // left pupil
let eyeY1 = 135 + (mouseY - 135) * 0.1;
let eyeX2 = 185 + (mouseX - 185) * 0.1; // right pupil
let eyeY2 = 135 + (mouseY - 135) * 0.1;
// pupils should stay in the boundaries of the eyes
let maxX1 = 115 + 5; // Left eye X boundaries
let minX1 = 115 - 5;
let maxY1 = 135 + 1.5; // Left eye Y boundararies
let minY1 = 135 - 1.5;
let maxX2 = 185 + 5; // Right eye X boundaries
let minX2 = 185 - 5;
let maxY2 = 135 + 1.5; // Right eye Y boundaries
let minY2 = 135 - 1.5;
// left eye - white part and pupil
noStroke();
fill(255);
ellipse(115, 135, 27, 10); // left eye
fill(79, 49, 30); // pupil color
eyeX1 = constrain(eyeX1, minX1, maxX1); // Keep the pupil in the eye boundary
eyeY1 = constrain(eyeY1, minY1, maxY1);
ellipse(eyeX1, eyeY1, 12, 12); // Left pupil
// right eye
noStroke();
fill(255);
ellipse(185, 135, 27, 10); // right eye
fill(79, 49, 30);
eyeX2 = constrain(eyeX2, minX2, maxX2); // keep the pupil in the eye boundary
eyeY2 = constrain(eyeY2, minY2, maxY2);
ellipse(eyeX2, eyeY2, 12, 12); // right pupil
// nose
fill(219, 171, 151);
triangle(150, 145, 140, 165, 160, 165);
// eyelashes
stroke(0, 0, 0);
strokeWeight(1);
// left eyelashes
line(110, 125, 100, 120);
line(110, 125, 105, 115);
line(110, 125, 115, 115);
// right eyelashes
line(190, 125, 200, 120);
line(190, 125, 190, 115);
line(190, 125, 180, 115);
// mouth
stroke(101, 67, 33);
fill(225, 160, 164);
beginShape();
//heart shape lips
vertex(146, 190);
bezierVertex(140, 185, 135, 200, 150, 215);
bezierVertex(165, 200, 160, 175, 150, 200);
endShape(CLOSE);
// ears
fill(232, 190, 172); // same skin color
ellipse(70, 150, 15, 30); // left ear
ellipse(230, 150, 15, 30); // right ear
// eyebrows
stroke(0, 0, 0);
strokeWeight(4);
arc(115, 120, 40, 20, PI, TWO_PI); //left eyebrow
arc(185, 120, 40, 20, PI, TWO_PI); // right eyebrow
// earrings
fill(255, 215, 0); // gold color
ellipse(70, 170, 8, 18); // left earring
ellipse(230, 170, 8, 18); // right earring
// body - shirt and neck
noStroke();
fill(80, 0, 0);
rect(75, 250, 150, 150, 30); // shirt
fill(229, 181, 161); // same skin color
arc(150, 250, 75, 40, 0, PI, CHORD); // round neckline
// body details - lines for arms
stroke(100, 100, 100);
strokeWeight(2);
line(110, 300, 110, 360);
line(190, 300, 190, 360);
// draw flowers on mouse click
for (let i = 0; i < flower_position.length; i++) {
drawFlower(flower_position[i].x, flower_position[i].y);
}
// confetti falling down if celebration has started
if (celeb_start) {
for (let i = 0; i < confetti.length; i++) {
confetti[i].y += confetti[i].speedY; // move the confetti down
confetti[i].x += confetti[i].speedX; // move the confetti horizontally to give a wavy effect
fill(confetti[i].color);
noStroke();
ellipse(confetti[i].x, confetti[i].y, 10, 10);
}
// removing confetti that has gone off the screen
confetti = confetti.filter(c => c.y < height);
}
// falling flowers after celebration
if (flower_count >= 5 && !celeb_start) {
celeb_start = true;
// pause for 1 second before the celebration starts
setTimeout(() => {
generateConfetti(); // start the confetti
}, 300);
// pause for 5 seconds after confetti
setTimeout(() => {
makeFlowersFall(); // making flowers fall
}, 3000); // confetti and delay time
}
// move the falling flowers
for (let i = 0; i < fall_flowers.length; i++) {
fall_flowers[i].y += fall_flowers[i].speedY; // make flowers fall
fall_flowers[i].x += fall_flowers[i].speedX; // adding horizontal drift to the flowers
drawFlower(fall_flowers[i].x, fall_flowers[i].y);
}
// removing flowers that have fallen off the screen
fall_flowers = fall_flowers.filter(f => f.y < height);
}
// drawing the flower at the given position
function drawFlower(x, y) {
stroke(0);
strokeWeight(2);
fill(255, 255, 255); // white petals
for (let i = 0; i < 5; i++) {
ellipse(x + cos(TWO_PI * i / 5) * 15, y + sin(TWO_PI * i / 5) * 15, 20, 20); // petals
}
fill(255, 255, 0); // yellow center
noStroke();
ellipse(x, y, 20, 20); // flower's center
}
// stores the mouse click position to display flowers
function mousePressed() {
if (!celeb_start) {
flower_position.push(createVector(mouseX, mouseY));
flower_count++; // increase flower count
}
}
// generate confetti falling down- random positions and colors
function generateConfetti() {
for (let i = 0; i < 100; i++) {
let x = random(width);
let y = random(-100, -10); // starts above the canvas
let confettiColor = color(random(255), random(255), random(255));
let speedX = random(-2, 2); // random horizontal speed
let speedY = random(2, 5); // vertical speed
confetti.push({ x, y, color: confettiColor, speedX, speedY });
}
}
// making flowers fall
function makeFlowersFall() {
for (let i = 0; i < flower_position.length; i++) {
let flower = flower_position[i];
let flowerSpeedX = random(-1, 1); // horizontal drift speed for flowers
let flowerSpeedY = random(2, 4); // vertical falling speed for flowers
fall_flowers.push({ x: flower.x, y: flower.y, speedX: flowerSpeedX, speedY: flowerSpeedY });
}
// clear the flowers from the initial array
flower_position = [];
}