xxxxxxxxxx
29
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
translate(width/2, height/2);
const maxLayers = 6;
const layers = constrain(map(mouseX, 0, width, 0, maxLayers), 0, maxLayers);
drawCircle(width/2, layers);
}
function drawCircle(radius, layers) {
circle(0, 0, radius * 2);
if(layers > 0) {
const NUM = 3;
const ratio = 24/52;
const ang = TAU / NUM;
const rad = radius * (1-ratio);
for(let i = 0; i < NUM; i ++) {
const a = ang * i - PI/2;
push();
translate(cos(a) * rad, sin(a) * rad);
drawCircle(radius * ratio, layers - 1);
pop();
}
}
}