xxxxxxxxxx
// make source code public
// schien@mail.ncku.edu.tw, Spring 2025
//
// a noisy spiral
// program for lectures on "The Wrong Way to Draw a Circle"
// schien@mail.ncku.edu.tw
// Fall 2018
// revised to create a bed of 100 flowers
// 20181125
//
// adjusting from var scoping to let scoping
// schien@mail.ncku.edu.tw, Spring 2023
//
let bg; //background color
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(12);
bg = color(0, random(30), random(50));
clearBackground();
}
function draw() {
// pause after 100 flowers
if (0===(frameCount%100)) {
noLoop();
//clearBackground();
}
drawFlower();
}
function clearBackground() {
bg = color(0, random(30), random(50));
background(bg);
}
function mouseReleased() {
clearBackground();
loop();
}
function drawFlower() {
// growing from within the canvas
let centerX = random(width);
let centerY = random(height);
// in various colors and pen width
stroke(random(100,255), random(180), random(70), 80);
strokeWeight(random(5));
noFill();
// initialize the flower
let x, y, rad=0;
let nextX, nextY, nextR=0;
let radius = 10;
let radiusNoise = random(10);
let startangle = random(360);
let endangle = 720 + random(900);
let anglestep = 5 + random(3);
// draw the flower
for (let ang=startangle; ang<endangle; ang+=anglestep) {
radius += 0.5;
radiusNoise += 0.05;
let thisR = radius + noise(radiusNoise)*100 - 50;
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;
}
}