JS viewer

Syntax-highlighted view of JS of World: Outer Space





// Cloned by Avril Hayden on 6 Oct 2019 from World "One Cube World (P5)" by Starter user 
// Please leave this clone trail here.
 
// make an array of random (x,y,z) positions 
 //const MUSICFILE = '/uploads/starter/SuspenseStrings.mp3';
 //AB.backgroundMusic ( MUSICFILE );

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

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

 
const objectsize    =  50;      // size of object   

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

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

var img;

function preload() 
{
   img = [loadImage (  "/uploads/starter/earth.1.jpg" ), loadImage ( "/uploads/avrilhayden/1570355961.png"), loadImage ("uploads/rossfraney3/mars.png"), loadImage ("uploads/alexmurphy1996/saturn2.jpg")];
  // bkimg = loadImage ("uploads/kelletelle/free_space_galaxy_texture_by_lyshastra-d77gh54.jpg");
 //  img1 = loadImage (  "/uploads/starter/earth.1.jpg" );
 //  img2 = loadImage ( "/uploads/avrilhayden/1570355961.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 
{

   // texture(img1);
    //texture(img2);

    background("gray");    // background color 
   // fill("red");               // paint box with this color 
           
    rotateX(angle);             // set each dimension rotation angle to "angle"
    rotateY(angle);
    rotateZ(angle);
  
    
   // box(objectsize);            // draw a cube of this size
   
    //sphere(50); 
    //translate(100, 100, 100);
    //sphere(objectsize); 

  for ( var i=0; i < noboxes; i++ )
{
  translate ( a[i][0], a[i][1], a[i][2] );		// get box position i 
  sphere(objectsize);
  texture(img[i]);
}
    angle = angle + anglechange ;       // change angle each step to get rotate movement        
}