xxxxxxxxxx
30
function setup() {
createCanvas(800, 800);
background(255);
}
function draw() {
noLoop();
drawStar(width / 2 - 100, height / 2 - 100, 5, 100, color(0, 0, 0));
drawStar(width / 2 + 100, height / 2 - 100, 6, 100, color(255, 255, 0));
drawStar(width / 2 - 100, height / 2 + 100, 7, 100, color(255, 0, 0));
drawStar(width / 2 + 100, height / 2 + 100, 8, 100, color(0, 0, 255));
}
function drawStar(x, y, points, radius, col) {
push();
translate(x, y);
stroke(col);
fill(col);
beginShape();
for (let i = 0; i < points * 2; i++) {
let angle = map(i, 0, points * 2, 0, TWO_PI);
let r = i % 2 === 0 ? radius : radius / 2;
let x = r * cos(angle);
let y = r * sin(angle);
vertex(x, y);
}
endShape(CLOSE);
pop();
}