xxxxxxxxxx
43
function setup() {
createCanvas(1200, 400);
background(255);
let centerY = height / 2;
let radius = 100;
for (let n = 0; n < 4; n++) {
push();
let centerX = n * 300 + 150;
translate(centerX, centerY);
// Define angles for each vertex
let angles = [];
let vertices = []; // Store vertices in an array
for (let i = 0; i < 5; i++) {
angles.push((TWO_PI / 5) * i - HALF_PI); // Rotate 90 degrees counterclockwise
let x = radius * cos(angles[i]);
let y = radius * sin(angles[i]);
vertices.push(createVector(x, y)); // Store the vertex in the array
}
// Connect every vertex with a thinner line
strokeWeight(2);
for (let i = 0; i < n+1; i++) {
let v1 = vertices[i];
for (let v2 of vertices) {
line(v1.x, v1.y, v2.x, v2.y);
}
}
for (let i = 0; i < 5; i++) {
let v = vertices[i].copy();
v.mult(1.2);
// Label the vertices
textSize(24);
textAlign(CENTER, CENTER);
noStroke();
fill(0);
text(i, v.x, v.y);
}
pop();
}
}