xxxxxxxxxx
34
// A demo that could potentially be used as
// a code example on the random() reference page:
// https://p5js.org/reference/p5/random/
// 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 demos of random2D() and random3D():
// https://editor.p5js.org/highermathnotes/sketches/uA5dfLIgM
// https://editor.p5js.org/highermathnotes/sketches/tbabFvQ6vt
let pts = [];
function setup() {
createCanvas(400, 400);
describe('A hundred points randomly distributed along a line segment.');
// create points on a line segment of length 300px
for (let i = 0; i < 100; i++) {
pts.push(createVector(random(300), 0));
}
}
function draw() {
background(220);
strokeWeight(2);
translate(50, height / 2);
for (let pt of pts) {
point(pt);
}
}