xxxxxxxxxx
34
// A demo that could potentially be used as
// a code example on the random2D() reference page:
// https://p5js.org/reference/p5.Vector/random2D/
// Use of for...of loop may need to be reconsidered,
// depending on style guidelines
// Advantages of this demo:
// 1. It shows the distribution, which can serve as a visual test.
// 2. It could be compared to the demo of random3D():
// https://editor.p5js.org/highermathnotes/sketches/tbabFvQ6vt
// 3. The code is simpler than in the existing visual example.
let pts = [];
function setup() {
createCanvas(400, 400);
describe('Hundreds of points are randomly distributed along a circle, revealing its shape.');
// create points on a circle of radius 150px
for (let i = 0; i < 250; i++) {
pts.push(p5.Vector.random2D().mult(150));
}
}
function draw() {
background(220);
strokeWeight(2);
translate(width / 2, height / 2);
for (let pt of pts) {
point(pt);
}
}