xxxxxxxxxx
// make source code public
// schien@mail.ncku.edu.tw, Spring 2025
//
// the baby-step way to draw a circle
// 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
//
// adjusted canvas, circle sizes
// schien@mail.ncku.edu.tw, Spring 2024
//
// turn it into a noisy spiral
// schien@mail.ncku.edu.tw, Spring 2024
//
function setup() {
createCanvas(800, 800);
noLoop();
}
function draw() {
background(255);
strokeWeight(4);
noFill();
let radius = 30;
let centerX = width / 2;
let centerY = height / 2
// the easy way
stroke(0, 30);
circle(centerX, centerY, 2 * radius);
// in steps
stroke(20, 50, 70);
let x, y, rad = 0;
let xn, yn, radn = 0;
let radiusNoise = random(10);
for (let ang = 0; ang < 360 * 9; ang += 5) {
radius += 1;
radiusNoise += 0.05;
let thisR = radius + noise(radiusNoise) * 200 - 100;
if (radn == rad) {
rad = radians(ang);
x = centerX + thisR * cos(rad);
y = centerY + thisR * sin(rad);
}
//point(x, y);
radn = radians(ang + 5);
xn = centerX + thisR * cos(radn);
yn = centerY + thisR * sin(radn);
line(x, y, xn, yn);
x = xn;
y = yn;
}
}