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 objectsize    = 200;      // size of object   

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

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


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("lightblue");    // background color 
    fill("navy");               // 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 
  
    angle = angle + anglechange ;       // change angle each step to get rotate movement
}
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.