xxxxxxxxxx
35
var points;
function setup() {
createCanvas(400, 400);
noStroke();
points = getShapePoints(3, 100, 90 * (PI / 180));
}
function draw() {
background(220);
push();
translate(width / 2, height / 2);
fill(255, 0, 255);
beginShape();
for(var i = 0; i < points.length; i++) {
var pt = points[i];
vertex(pt.x, pt.y);
}
endShape();
pop();
}
function getShapePoints(sides, radius, rotation) {
var angleStepSize = TWO_PI / sides;
var points = [];
for(var i = 0; i < sides; i++) {
points.push({
x: radius * cos(rotation + i * angleStepSize),
y: radius * sin(rotation + i * angleStepSize)
});
}
return points;
}