xxxxxxxxxx
// make source code public
// schien@mail.ncku.edu.tw, Spring 2025
//
// 100 spirals with random starting/ending/stepping controls
// program for lectures on "The Wrong Way to Draw a Circle"
// schien@mail.ncku.edu.tw
// Fall 2018
//
// adjusted for let/var differenciation (prefer let scoping)
// schien@mail.ncku.edu.tw, Spring 2023
//
function setup() {
createCanvas(500, 300);
noLoop();
}
function draw() {
background(255);
strokeWeight(0.5);
noFill();
let radius;
let centerX = width/2;
let centerY = height/2
stroke(0, 30);
for (let i=0; i<100; i++) {
let x, y, rad=0;
let nextX, nextY, nextR=0;
radius = 10;
let radiusNoise = random(10);
let startAngle = random(360);
let endAngle = 1440 + random(1440);
let angleStep = 5 + random(3);
for (let ang=startAngle; ang<endAngle; ang+=angleStep) {
radius += 0.5;
radiusNoise += 0.05;
let thisR = radius + noise(radiusNoise)*200 - 100;
if (nextR === rad) {
rad = radians(ang);
x = centerX + thisR * cos(rad);
y = centerY + thisR * sin(rad);
}
nextR = radians(ang+5);
nextX = centerX + thisR*cos(nextR);
nextY = centerY + thisR*sin(nextR);
line(x, y, nextX, nextY);
x = nextX;
y = nextY;
}
}
}