xxxxxxxxxx
// schien@mail.ncku.edu.tw, DPD2025
// a bed of 100 flowers
// converted by ChatGPT from https://openprocessing.org/sketch/44803
let counter = 0; // flower counter
function setup() {
createCanvas(500, 300);
background(255);
smooth();
clearBackground();
}
function draw() {
// refresh the screen if more than 100 flowers are drawn
if (counter > 100) {
clearBackground();
counter = 0;
}
drawSpiral();
frameRate(3); // Adjusted to delay, p5.js uses frameRate instead of delay.
counter++;
}
function drawSpiral() {
let x, y;
let centX = random(width);
let centY = random(height);
let lastx = -999;
let lasty = -999;
let radiusNoise = random(10);
let radius = 10;
// Random stroke color and weight
stroke(random(100, 255), random(255), random(70), 80);
strokeWeight(random(5));
let startangle = random(360);
let endangle = 720 + random(720);
let anglestep = 5 + random(3);
for (let ang = startangle; ang <= endangle; ang += anglestep) {
radiusNoise += 0.05;
radius += 0.5;
let thisRadius = radius + (noise(radiusNoise) * 100) - 50;
let rad = radians(ang);
x = centX + (thisRadius * cos(rad));
y = centY + (thisRadius * sin(rad));
if (lastx > -999) {
line(x, y, lastx, lasty);
}
lastx = x;
lasty = y;
}
}
function clearBackground() {
background(255);
}
function mousePressed() {
saveCanvas('spiral', 'png');
clearBackground();
}