Code viewer for World: The Big Bang

// Cloned by Mervin Shibu George on 18 Sep 2024 from World "One Cube World (P5)" by Starter user 
// Please leave this clone trail here.
 
 
 var img;
 
const objectsize    = 8;      // size of object   

const anglechange   = 0.01;     // how much the rotate angle changes each step 

var angle = 0;                  // rotate angle starts at 0  

function randomUnitVector3D() {
  let theta = Math.random() * 2 * Math.PI; // Random angle in the XY plane
  let phi = Math.acos(2 * Math.random() - 1); // Random angle for Z axis
  return {
    x: Math.sin(phi) * Math.cos(theta),
    y: Math.sin(phi) * Math.sin(theta),
    z: Math.cos(phi)
  };
}

const count = 150;
sphere_vectors = Array(count);
for (let i = 0; i < count; i++) {
    sphere_vectors[i] = randomUnitVector3D();
}
var cycle = 0;
var cycleSpeed = 5;


function preload() 
{
   img = loadImage ( '/uploads/ajsweeney/agentglow.png' );
}

function setup()        // "setup" is called once at start of run 
{
  createCanvas ( ABWorld.fullwidth(), ABWorld.fullheight(),  WEBGL );
}

function draw()         // "draw" is called every timestep during run 
{
    background("#070e17");    // background color 
    fill("#eaebe6");               // paint box with this color 
    // texture(img);        	
    noStroke();

           
    // rotateX(angle);             // set each dimension rotation angle to "angle"
    // rotateY(angle);
    // rotateZ(angle);
    
    translate(0, 0, 0);
    // sphere(objectsize);            // draw a cube of this size 
    rotateX(angle);
    for(let vector of sphere_vectors) {
        let x = vector.x * cycle;
        let y = vector.y * cycle;
        let z = vector.z * cycle;
        translate(x,y,z);
        sphere(objectsize);
        translate(-x, -y, -z);
    }
    // orbitControl();
    cycle = cycle + cycleSpeed;
    
    
    // angle = angle + anglechange ;       // change angle each step to get rotate movement
}