Ancient Brain
  
Drag the background!
 

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 );
};

 
The background is a program, showing the JavaScript graphics used on this site.
The globes light up when you log in. Drag the background to move the camera.
Customise background:  
Font:

Website © Ancient Brain 2025.
Users retain ownership of user content.

Platforms      Stats      The name      Terms and conditions

Call for partners      Contact

Call for partners!
Ancient Brain is looking for a partner to co-write a JavaScript coding book for schools, to be used worldwide. This would be a course for students in learning to code from scratch. The book and course will be integrated into the Ancient Brain site. This is an opportunity for someone looking to develop a course and textbook to partner with a site to promote it. Read more.