xxxxxxxxxx
56
function setup(){
// frameRate(12);
createCanvas(400,400)
background(220, 255, 220);
noStroke();
fill(255,100,255);
polygon(X,Y,R,N, t);
}
var X = 200;
var Y = 200;
var R = 100;
var N = 6;
var t = 0;
function draw() {
background(220,255,220);
fill(255,100,255);
polygon(X,Y,R,N, t);
fill(0);
text("theta = " + nf(-t * 180 / PI,0,2), 200, 200);
}
function keyPressed() {
if (keyCode == UP_ARROW) {
t = t - PI/90;
}
}
function polygon(x, y, radius, npoints, theta) {
//degrees = radians × 180° / π
//radians = degrees × π /180°
var angle = TWO_PI / npoints; // TWO_PI is the equivalent of 360 degrees
console.log("radians: " + angle);
console.log("degrees: " + (angle *180/PI));
beginShape();
for (var a = theta; a <= TWO_PI; a = a + angle) {
var sx = x + cos(a) * radius;
var sy = y + sin(a) * radius;
vertex(sx, sy);
console.log("sx, sy: " + sx + ", " + sy);
}
endShape();
}