xxxxxxxxxx
96
// Blooming Emoji Garden - Generative Artwork
// Created using p5.js and Object-Oriented Programming
let shapes = []; // Array to store all emoji objects
const numShapes = 30; // Number of emojis to create
const emojis = ["🌸", "🌺", "🌻", "🌼", "🌷", "🍄", "🐝", "🐞", "🦋"]; // List of emojis to use
function setup() {
createCanvas(800, 800);
textSize(50); // Set emoji size
textAlign(CENTER, CENTER);
// Initialize emojis
for (let i = 0; i < numShapes; i++) {
let x = random(width); // Random x position
let y = random(height); // Random y position
let size = random(30, 80); // Random initial size
let emoji = random(emojis); // Random emoji
let col = color(random(100, 255), random(100, 255), random(100, 255), 200); // Random color with transparency
shapes.push(new BloomingEmoji(x, y, size, emoji, col)); // Add new emoji to the array
}
}
function draw() {
background(30); // Dark background
// Update and display all emojis
for (let emoji of shapes) {
emoji.update();
emoji.display();
emoji.checkNeighbors(shapes); // Check for interactions with other emojis
}
}
// Add a new emoji when the mouse is clicked
function mousePressed() {
let size = random(30, 80); // Random size
let emoji = random(emojis); // Random emoji
let col = color(random(100, 255), random(100, 255), random(100, 255), 200); // Random color
shapes.push(new BloomingEmoji(mouseX, mouseY, size, emoji, col)); // Add new emoji at mouse position
}
// BloomingEmoji class
class BloomingEmoji {
constructor(x, y, size, emoji, col) {
this.x = x; // X position
this.y = y; // Y position
this.size = size; // Size of the emoji
this.emoji = emoji; // Emoji character
this.col = col; // Color of the emoji
this.growthRate = random(0.1, 0.5); // Rate at which the emoji grows
this.maxSize = random(80, 150); // Maximum size the emoji can grow to
this.angle = random(TWO_PI); // Random initial angle for rotation
this.rotationSpeed = random(-0.05, 0.05); // Random rotation speed
}
// Update the emoji's size, color, and rotation
update() {
this.size += this.growthRate; // Grow the emoji
if (this.size > this.maxSize) {
this.size = this.maxSize; // Limit the size
}
this.col = color(
red(this.col),
green(this.col),
blue(this.col),
map(this.size, 30, this.maxSize, 200, 50) // Fade as it grows
);
this.angle += this.rotationSpeed; // Rotate the emoji
}
// Display the emoji
display() {
push();
translate(this.x, this.y); // Move to emoji position
rotate(this.angle); // Rotate the emoji
fill(this.col);
textSize(this.size);
text(this.emoji, 0, 0); // Draw the emoji
pop();
}
// Check for interactions with neighboring emojis
checkNeighbors(shapes) {
for (let other of shapes) {
if (other !== this) { // Avoid self-comparison
let d = dist(this.x, this.y, other.x, other.y); // Distance between emojis
if (d < (this.size + other.size) / 2) { // If emojis overlap
this.growthRate *= 0.99; // Slow down growth
this.x += random(-2, 2); // Add a little jiggle
this.y += random(-2, 2);
}
}
}
}
}