xxxxxxxxxx
61
let angle = 0;
let cellSize;
let increment = 0.1; // Increased rate at which the angle changes
let direction = 1; // 1 for increasing, -1 for decreasing
let margin = 30; // Define a smaller margin for all sides
function setup() {
createCanvas(422, 596);
fill(250, 90, 190);
strokeWeight(1);
frameRate(7); // Set frame rate for animation
}
function draw() {
background(80, 210, 150);
// Set a smaller cellSize to create more cells
cellSize = min((width - 2 * margin) / 10, (height - 2 * margin) / 10);
// Calculate how many cells fit within the available area (excluding margin)
let numCols = floor((width - 2 * margin) / cellSize);
let numRows = floor((height - 2 * margin) / cellSize);
// Calculate the starting position to center the grid
let startX = (width - numCols * cellSize) / 2;
let startY = (height - numRows * cellSize) / 2;
// Loop through to draw the grid
for (let y = 0; y < numRows; y++) {
for (let x = 0; x < numCols; x++) {
push();
// Center the ellipses and apply rotation and scaling
translate(startX + x * cellSize + cellSize / 2, startY + y * cellSize + cellSize / 2);
let rotateAmount = random(-angle, angle); // Apply exaggerated random rotation
rotate(rotateAmount);
// Add scaling to make the ellipses animate in size too
let scaleFactor = 1 + 0.5 * sin(angle * 3); // Smooth oscillation for scaling
scale(scaleFactor);
// Draw the ellipse
ellipse(0, 0, cellSize, cellSize); // Regular ellipse, size adjusted by scaling
pop();
}
}
// Gradually increase or decrease the angle based on the direction
angle += increment * direction;
// Change the direction if the angle reaches a certain limit
if (angle >= 1 || angle <= 0) { // Increased angle range for more exaggerated animation
direction *= -1; // Reverse the direction of the angle change
}
}
function keyPressed() {
if (key === 's') saveGif('animation.gif', 5); // Save the animation on keypress 's'
}