xxxxxxxxxx
45
let angle;
var step; //distance between steps in radians
let randomColor;
let distance;
let stepCount = 90; // an interval of 360, 180, 90, 60, 45
function setup() {
createCanvas(500, 500);
distance = 50; // Distance from enter
angle = 0; // Current angle around circle
step = TWO_PI / stepCount; // How many steps around circle
translate(width / 2, height / 2);
drawLayer(0, 10, "red");
drawLayer(1, 10, "green");
drawLayer(2, 10, "blue");
drawLayer(3, 10, "purple");
}
function drawLayer(layerNumber, lineLength, c) {
stroke(c);
let w = width / 2;
for (let i = 0; i < stepCount; i++) {
// Convert polar coordinates to cartesian coordinates
var x = distance * sin(angle);
var y = distance * cos(angle);
// Draw line so it is "pointed" towards the center
line(
x + sin(angle) * lineLength * layerNumber,
y + cos(angle) * lineLength * layerNumber,
x + sin(angle) * lineLength * (layerNumber - 1),
y + cos(angle) * lineLength * (layerNumber - 1)
);
// Move to next angle
angle = angle + step;
}
}
function draw() {}