xxxxxxxxxx
42
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255);
fill('#0af')
circle(200,200,300)
push();
translate(width * 0.5, height * 0.5);
fill(255)
let t=3
if(mouseX/20>t)
{
t=mouseX/20
}
polygon(0, 0, 150,t);
pop();
push()
fill(0)
text((t*sin(180/t))+3,200,200)
pop()
text('the value is less acurate when sides are unequal',100,370)
}
function polygon(x, y, radius, npoints) {
let angle = TWO_PI / npoints;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius;
let sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}