xxxxxxxxxx
63
// Global variables
let radius = 0;
let angle = 0;
let numArms;
let deltaRadius;
let deltaAngle;
let curve;
let hue;
let hueChanger;
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
angleMode(DEGREES);
// Call reset to init all variables
reset();
}
function draw() {
translate(width / 2, height / 2);
// update angle and radius
angle += deltaAngle;
radius += deltaRadius;
// get position from polar coordinates
x = radius*cos(angle)
y = radius*sin(angle)
// update colours
hue += hueChanger;
colorMode(HSB);
// draw the point
strokeWeight(10);
stroke(color(hue,60,100))
point(x, y);
// bounce colours
if(hue>360){
hue = 0;
}
// Get the spiral to come inwards forming a flower
if (radius > height / 2 - 25) {
deltaRadius = -deltaRadius;
}
if (radius < 0) {
reset();
}
}
function reset() {
background(0);
deltaRadius = random(0.5,1);
numArms = floor(random(3,8))
curve = random(0.3,1);
// Number of arms/360 + curve to make the arms curve a little
deltaAngle = 360 / numArms + curve;
hue = random(0, 360);
hueChanger = random(1,5);
}