xxxxxxxxxx
48
//You can change r and you can change n...you can change anything, but those are the big things.
let r = 90; //radius
let ang; //central angle
let n = 3; //number of sides
let v = 0; //v controls rotating
let area;
function setup() {
createCanvas(400, 400);
angleMode(RADIANS);
ang = (2 * PI) / n;
//v = ang;
}
function draw() {
background(0);
stroke(255);
strokeWeight(3);
noFill();
//creating the shape
beginShape();
for (var i = 0; i < n; i++) {
vertex(
width / 2 + r * cos(ang * i + v),
height / 2 + r * sin(ang * i+v)
);
}
endShape(CLOSE);
//creating the spokes
strokeWeight(1)
for (var i = 0; i < n; i++) {
line(width/2,height/2,width / 2 + r * cos(ang * i + v),
height / 2 + r * sin(ang * i +v))
}
v += .002; //rate of rotation
area = n*1/2*r*r*sin(ang);
text('Area = ' + area,10,40)
//console.log(area);
}