xxxxxxxxxx
29
/*
* Creative Coding Workshop #3 Demo - Circle Formed by Vertices
*
* Jack B. Du (github@jackbdu.com)
*/
function setup() {
// create a 400px by 400px canvas
createCanvas(400, 400);
}
function draw() {
// specify a background for each frame
background(220);
// specify the number of circles
let num = 10;
// specify the radius of formed circle
let radius = 100;
// translate origin to center
translate(width/2, height/2);
beginShape();
// for loop that repeats from 0 to num-1
for (let i = 0; i < num; i++) {
// draw circles that form a circle
// circle(radius*sin(TWO_PI*i/num), radius*cos(TWO_PI*i/num), 10);
// add vertex that form a circle
vertex(radius*sin(TWO_PI*i/num), radius*cos(TWO_PI*i/num));
}
endShape(CLOSE);
}