xxxxxxxxxx
83
function setup(){
frameRate(12);
createCanvas(windowWidth,windowHeight);
}
var N = 4;
var R = 100;
var X = 200;
var Y = 200;
function draw() {
background(240, 240, 255);
stroke(0,0,255);
fill(255);
module(width/2, height/2, 200);
//let s = map(d, 100, 0, 0, 100);
//s = constrain(s, 0, 20);
//console.log(s);
// if (s < 0) { s = 0; };
// ellipse(x, y, s*2, s*2);
//line(x, y, mouseX, mouseY);
//text(d, x, y);
//polygon(width/2, height/2, 100, s);
}
function module(x , y , r) {
let d = dist(x, y, mouseX, mouseY);
d = floor(d); // floor, round, ceil
let n = map(d, 1, 400, 4, 20);
n = floor(n);
let s = map(d, 100, 0, 0, 100);
s = constrain(s, 0, 100);
// if (s < 0) { s = 0; };
/*
push();
translate(x,y);
//ellipse(0,0,10,10);
line(0,0,0, -s);
push();
translate(0,-2);
pop();
pop();
*/
polygon(x, y, r, n);
// ellipse(x, y, s*2, s*2);
line(x, y, mouseX, mouseY);
text(n, x, y);
}
function polygon(x, y, radius, npoints) {
//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 = 0; 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();
}