xxxxxxxxxx
35
let n = 8;
let r = 10;
let old_mx = -1;
let old_my = -1;
function setup() {
createCanvas(800, 400);
background(0);
for (let ni = 0;ni< 1000; ni++){
let r_s = random()*5;
noStroke();
fill(255,200);
ellipse(random()*width,random()*height,r_s,r_s);
}
}
function draw() {
if (mouseIsPressed) {
let mx = mouseX;
let my = mouseY;
if (old_mx >= 0 && old_my >= 0) {
for (let ni = 0; ni < n; ni++) {
noStroke();
strokeWeight(2);
stroke(255, 226, 0);
line(old_mx + r*cos(TWO_PI*ni/n), old_my + r*sin(TWO_PI*ni/n), mx + r*cos(TWO_PI*ni/n), my + r*sin(TWO_PI*ni/n));
}
}
old_mx = mx;
old_my = my;
} else {
old_mx = -1;
old_my = -1;
}
}