xxxxxxxxxx
38
/*
* Contains a spiral function
* and draws some of them, with various parameters
*
* Demonstrates reusable function
*/
function setup() {
createCanvas(600, 600);
colorMode(HSB, 360, 100, 100);
background(0,0,0);
noStroke();
}
function draw() {
background(0,0,0);
strokeWeight(10);
noFill();
// x, y, hue, lps, dots, r, dw, tilt
drawSpiral(width/2-150, height/2-150, 50, 2, 100, 100, 5, 0.0); // top left
drawSpiral(width/2+150, height/2-150, 100, 4, 100, 100, 5, 1.5); // top right
drawSpiral(width/2-150, height/2+150, 150, 6, 100, 100, 5, 3.0); // bottom left
drawSpiral(width/2+150, height/2+150, 200, 8, 100, 100, 5, 4.5); // bottom right
drawSpiral(width/2, height/2, 300, 2, 50, 100, 5, 4.5); // centre
}
function drawSpiral(x, y, hue, numLoops, numDots, radius, dotWidth, tilt){
fill(hue, 70, 100);
let angleGap = (TWO_PI * numLoops) / numDots; // Calc how far apart
let radiusGap = radius / numDots; // the dots should be
for (let i = 0; i < numDots; i++){ // Draw dots in the spiral
let dotX = x + (i*radiusGap) * sin((i*angleGap) + tilt);
let dotY = y + (i*radiusGap) * cos((i*angleGap) + tilt);
ellipse(dotX, dotY, 5, 5);
}
}