xxxxxxxxxx
34
function setup() {
createCanvas(600, 600);
strokeWeight(2);
}
function draw() {
background(220);
push();
translate(width/2, height/2);
circle(0, 0, width);
const multiple = int(map(mouseX, 0, width, 2, 9));
drawLines(200, multiple);
pop();
}
// n = num points around circle
// m = times table
function drawLines(n, m) {
const radius = width/2;
for(let i = 0; i < n; i ++) {
const j = (i * m);
let ang_i = getAngle(i, n);
let ang_j = getAngle(j, n);
line(cos(ang_i) * radius, sin(ang_i) * radius,
cos(ang_j) * radius, sin(ang_j) * radius);
}
}
function getAngle(i, numPoints) {
return (TAU/numPoints) * i;
}