xxxxxxxxxx
30
// A demo that could potentially be used as
// a code example on the random3D() reference page:
// https://p5js.org/reference/p5.Vector/random3D/
// Description adapted from an example on the orbitControl() page:
// https://p5js.org/reference/p5/orbitControl/
// Use of for...of loop may need to be reconsidered, depending on
// style guidelines
let pts = [];
function setup() {
createCanvas(400, 400, WEBGL);
describe('Thousands of points are randomly distributed on the surface of a sphere, revealing its shape. The camera angle changes when the user interacts using a mouse, trackpad, or touchscreen.');
// create points on a sphere of radius 150px
for (let i = 0; i < 2500; i++) {
pts.push(p5.Vector.random3D().mult(150));
}
}
function draw() {
background(220);
orbitControl();
for (let pt of pts) {
point(pt);
}
}