xxxxxxxxxx
40
//midterm progress by SP
let numSpirals = 10;
let angleOffset = 0;
let maxRadius = 200;
function setup() {
createCanvas(windowWidth, windowHeight);
noFill();
strokeWeight(2);
}
function draw() {
background(0, 30);
translate(width / 2, height / 2);
for (let i = 0; i < numSpirals; i++) {
// Dynamic color based on spiral index
stroke(map(i, 0, numSpirals, 100, 255), 100, 255, 150);
beginShape();
for (let angle = 0; angle < TWO_PI * 10; angle += 0.1) {
let radius = map(sin(angle * 2 + angleOffset), -1, 1, 50, maxRadius); // Vary radius
let x = radius * cos(angle + i * (TWO_PI / numSpirals)); // X position
let y = radius * sin(angle + i * (TWO_PI / numSpirals)); // Y position
vertex(x, y);
}
endShape();
}
angleOffset += 0.02; // increment the angle offset for animation
// interactivity: Change maximum radius based on mouse position
maxRadius = map(mouseX, 0, width, 50, 300);
}
// adjust canvas size on window resize
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}