xxxxxxxxxx
30
function setup()
{
createCanvas(64, 64);
loadPixels();
for (let i = 0; i < pixels.length; i += 4)
{
let v = RandomVector();
pixels[i + 0] = 127 * v.x + 128;
pixels[i + 1] = 127 * v.y + 128;
pixels[i + 2] = 127 * v.z + 128;
pixels[i + 3] = 255;
}
updatePixels();
}
function RandomVector()
{
let phi = random(0, TAU);
let cosTheta = random(0, 1);
let theta = acos(cosTheta);
let x = sin(theta) * cos(phi);
let y = sin(theta) * sin(phi);
let z = cos(theta);
return {x:x, y:y, z:z};
}