xxxxxxxxxx
34
dots = [];
maxR = 100;
function setup() {
createCanvas(600, 600);
makeDots(800);
}
function draw() {
background(220);
for (var i = 0; i < dots.length; i++){
strokeWeight(5);
point(dots[i].x, dots[i].y);
}
strokeWeight(1);
noFill();
}
function makeDots(n){
// choose random radius and angle from the center
for (var i = 0; i < n; i++){
a = random(0, 2*PI);
// https://programming.guide/random-point-within-circle.html
// we use square root of random for equal distribution of points from the center
r = 20 * sqrt(random(0, maxR));
x = width/2 + r * cos(a);
y = height / 2 + r * sin(a);
var newDot = createVector(x, y);
dots.push(newDot);
}
}