Spaces:
Running
Running
| let flickerRate = 40; // 40 Hz flicker rate | |
| let angle = 0; // For rotation | |
| let isBright = true; // Toggle between bright and dark states | |
| function setup() { | |
| createCanvas(windowWidth, windowHeight); | |
| frameRate(flickerRate); // Set to 40 Hz | |
| rectMode(CENTER); // Center shapes for rotation | |
| background(0); | |
| } | |
| function draw() { | |
| // Flicker between two states | |
| if (isBright) { | |
| background(255); // Bright background | |
| } else { | |
| background(0); // Dark background | |
| } | |
| isBright = !isBright; // Toggle | |
| // Add rotating grid of shapes | |
| let gridSize = 80; // Size of grid cells | |
| translate(width / 2, height / 2); // Move to center | |
| rotate(angle); // Apply rotation | |
| angle += 0.02; // Slow rotation speed | |
| for (let x = -width; x < width; x += gridSize) { | |
| for (let y = -height; y < height; y += gridSize) { | |
| // Alternate colors based on flicker state and position | |
| if ((floor(x / gridSize) + floor(y / gridSize)) % 2 === 0) { | |
| fill(isBright ? 0 : 255); // Inverse of background | |
| } else { | |
| fill(isBright ? 255 : 0); | |
| } | |
| noStroke(); | |
| // Draw rotating rectangles and circles | |
| push(); | |
| translate(x, y); | |
| rotate(angle * 0.5); // Additional rotation for each shape | |
| rect(0, 0, gridSize * 0.6, gridSize * 0.6); // Square | |
| pop(); | |
| // Overlay smaller flickering circles | |
| fill(isBright ? 255 : 0); // Opposite color for contrast | |
| ellipse(x, y, gridSize * 0.3); // Circle | |
| } | |
| } | |
| } | |
| function windowResized() { | |
| resizeCanvas(windowWidth, windowHeight); | |
| } | |