Code viewer for World: P5 Starter Tutorial: Part 2

// Cloned by Tristan Everitt on 19 Sep 2022 from World "One Cube World (P5) (clone by Tristan Everitt)" by Tristan Everitt 
// Please leave this clone trail here.
 


// Cloned by Tristan Everitt on 19 Sep 2022 from World "One Cube World (P5)" by Starter user 
// Please leave this clone trail here.
 
 
const objectsize    = 150;      // size of object   

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

let speed = 1;

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

const MUSICFILE = '/uploads/starter/SuspenseStrings.mp3';
AB.backgroundMusic ( MUSICFILE );


var img;

// make an array of random (x,y,z) positions 

const noboxes = 300;                 	// how many boxes to have 
var a = new Array(noboxes);         	// array of the box positions

var colour = "#A52A2A";

for ( var i=0; i < noboxes; i++ )   	// set up the array
{
    a[i] = [ AB.randomIntAtoB(-250,250), AB.randomIntAtoB(-250,250), AB.randomIntAtoB(-250,250) ];
}	


function draw()         // "draw" is called every timestep during run 
{
    background(colour);    // background color 
    texture(img);        	
     
    rotateX(angle);             // set each dimension rotation angle to "angle"
    rotateY(angle);
    rotateZ(angle);
  
    //box(objectsize);            // draw a cube of this size 
  
    if(AB.randomIntAtoB(0,100) === 50) {
        speed = speed > 1 ? 1 : AB.randomIntAtoB(1,10);
        colour = "rgb("+AB.randomIntAtoB(0,255)+","+AB.randomIntAtoB(0,255)+","+AB.randomIntAtoB(0,255)+")"
    }
    angle = angle - (anglechange * speed) ;       // change angle each step to get rotate movement
    

    for ( var i=0; i < noboxes; i++ )
    {
      translate ( a[i][0], a[i][1], a[i][2] );		// get box position i 
      box(objectsize);             
    }

}


function preload() 
{
   img = loadImage ( '/uploads/tristan/Rotating_black_and_white_squares.gif' );
}


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