Step 5. First look at the code

The editor shows the JavaScript code, which is also shown below.

If you have never seen JavaScript (or any program) before, here is what you are looking at:

  1. The program is a set of instructions for the computer to "execute".
  2. This is real JavaScript code. You can write in here anything that can be written in JavaScript.
  3. Instructions end with ";". This is important.
  4. You can insert blank lines, spaces and tabs in order to change the program layout and normally it does not matter. The program will still work the same.
  5. You can insert "comments". These begin with "//" and continue to the end of line. These are notes to the human reader and are ignored by the computer.
There is a lot to learn about JavaScript but you do not need to learn it all before trying some programming.
 
const skycolor          = 'lightblue';           
const boxcolor          = 'maroon';

const objectsize    = 300;                  // size of object   

const startRadius   = 1000;                 // distance from centre we start the camera at

const maxRadius     = startRadius * 10;     // maximum distance from camera we render things 


// the object is a cube (each dimension equal): 
  
var shape       = new THREE.BoxGeometry ( objectsize, objectsize, objectsize );
var material    = new THREE.MeshBasicMaterial ( { color: boxcolor.toLowerCase() } );
var theobject   = new THREE.Mesh ( shape, material );


// Define what the World does at the start of a run: 

AB.world.newRun = function() 
{
    // start a 3D scene: 
    ABWorld.init3d ( startRadius, maxRadius, skycolor ); 

    // add the object to the scene:
    ABWorld.scene.add ( theobject );
};