let particles = [];
const numParticles = 200;
let flowerColor; // Define flowerColor
let centerColor; // Define centerColor
function setup() {
createCanvas(600, 600);
flowerColor = color(255, 100, 0); // Vivid orange
centerColor = color(255, 200, 0); // Yellow-orange
// Initialize particles
for (let i = 0; i < numParticles; i++) {
particles.push(new Particle(width / 2, height / 2)); // Start at center
}
background(100);
}
function draw() {
background(100, 10); // Subtle trails
// Draw stems (simplified rectangles)
fill(70, 150, 70);
noStroke();
rect(width / 2 - 10, height * 0.5, 20, height * 0.5); // Main stem
rect(width / 4 - 5, height * 0.6, 10, height * 0.4); // Side stem
rect(width * 0.75 - 5, height * 0.6, 10, height * 0.4); // Side stem
// Update and display particles
for (let particle of particles) {
particle.update();
particle.display();
}
}
class Particle {
constructor(x, y) {
this.pos = createVector(x, y);
this.vel = p5.Vector.random2D();
this.vel.mult(random(0.5, 2)); // Initial speed
this.acc = createVector(0, 0);
this.size = 4;
this.maxSpeed = 4;
}
update() {
// Mouse attraction
let mouse = createVector(mouseX, mouseY);
let dir = p5.Vector.sub(mouse, this.pos);
dir.normalize();
dir.mult(0.3); // Attraction strength
this.acc = dir; // Set acceleration towards the mouse
this.vel.add(this.acc);
this.vel.limit(this.maxSpeed); // Limit speed
this.pos.add(this.vel);
// Keep particles within bounds (bounce effect)
if (this.pos.x < 0 || this.pos.x > width) {
this.vel.x *= -1;
}
if (this.pos.y < 0 || this.pos.y > height) {
this.vel.y *= -1;
}
// Reset position if particle goes too far from center
let distanceToCenter = dist(this.pos.x, this.pos.y, width / 2, height / 2);
if (distanceToCenter > 300) {
this.pos.x = width / 2 + random(-5, 5);
this.pos.y = height / 2 + random(-5, 5);
this.vel = p5.Vector.random2D();
this.vel.mult(random(0.5, 2));
}
}
display() {
// Color based on angle from center
let angle = atan2(this.pos.y - height / 2, this.pos.x - width / 2);
let hue = map(angle, -PI, PI, 0, 60); // Orange hues
colorMode(HSB, 360, 100, 100);
fill(hue, 80, 90); // Saturated orange/yellow
noStroke();
ellipse(this.pos.x, this.pos.y, this.size, this.size);
colorMode(RGB, 255); // Reset color mode
}
}