xxxxxxxxxx
86
let ripples = [];
let lotuses = [];
let caustics = [];
function setup() {
createCanvas(800, 600);
noSmooth(); // Pixel style for the overall aesthetic
// Initialize caustics grid
for (let i = 0; i < width; i += 20) {
for (let j = 0; j < height; j += 20) {
caustics.push({ x: i, y: j, offset: random(TWO_PI) });
}
}
}
function draw() {
background(0, 0, 150); // Deep blue water
// Draw caustics
drawCaustics();
// Draw and update all ripples
for (let i = ripples.length - 1; i >= 0; i--) {
let ripple = ripples[i];
drawRipple(ripple.x, ripple.y, ripple.size);
ripple.size += 2;
if (ripple.size > 100) {
// Add a new lotus when the ripple is big enough
lotuses.push({ x: ripple.x, y: ripple.y, frame: 0 });
ripples.splice(i, 1);
}
}
// Draw and animate blooming lotuses
for (let lotus of lotuses) {
drawBloomingLotus(lotus.x, lotus.y, lotus.frame);
if (lotus.frame < 30) lotus.frame++; // Stop increasing the frame after full bloom
}
}
function mousePressed() {
ripples.push({ x: mouseX, y: mouseY, size: 10 });
}
function drawRipple(x, y, size) {
noFill();
stroke(255, 255, 255, 100); // White with transparency
strokeWeight(2);
ellipse(x, y, size, size);
}
function drawBloomingLotus(x, y, frame) {
push();
translate(x, y);
// Scale lotus petals over time to simulate blooming
let scaleAmount = map(frame, 0, 30, 0, 1);
noStroke();
// Pink petals made with circles
fill(255, 182, 193);
for (let angle = 0; angle < TWO_PI; angle += PI / 6) { // 12 circles for petals
let petalX = cos(angle) * 30 * scaleAmount;
let petalY = sin(angle) * 30 * scaleAmount;
ellipse(petalX, petalY, 20 * scaleAmount, 20 * scaleAmount);
}
// Center of the flower
fill(255, 105, 180); // Darker pink for the center
ellipse(0, 0, 20 * scaleAmount, 20 * scaleAmount);
pop();
}
function drawCaustics() {
noStroke();
fill(255, 255, 255, 30); // Soft white for caustics
for (let caustic of caustics) {
let wave = sin(frameCount * 0.05 + caustic.offset) * 5;
ellipse(caustic.x + wave, caustic.y + wave, 15, 15);
}
}