Code viewer for World: Yet Another Sphere World

// Cloned by Michael Walsh on 20 Sep 2022 from World "One Cube World (Three.js)" by Starter user 
// Please leave this clone trail here.


const skycolor          = 'lightblue'; 
const objectsize    = 100;                  // size of object   
const startRadius   = 1000;                 // distance from centre we start the camera at
const maxRadius     = 0;//startRadius * 10;     // maximum distance from camera we render things 
const SPEED = 55;
const LIMIT = 150;

// the object is a cube (each dimension equal): 
var shape       = new THREE.SphereGeometry( 200, 32, 16 );
var material    = new THREE.MeshBasicMaterial ( { color: "#0000ff", wireframe: true } );

ABHandler.MouseUp = function (e) {
    console.log(e);
}


class Ball {
  constructor() {
    this.ball = new THREE.Mesh ( shape, material );
    this.ball.position.x = AB.randomFloatAtoB(-LIMIT, LIMIT);
    this.ball.position.y = AB.randomFloatAtoB(-LIMIT, LIMIT);
    this.ball.position.z = 0; //AB.randomFloatAtoB(-LIMIT, LIMIT);
    
    this.xDir = AB.randomFloatAtoB(0, SPEED);
    this.yDir = Math.sqrt((SPEED ** 2) - (this.xDir ** 2));

    this.xDir *= AB.randomPick(1, -1);
    this.yDir *= AB.randomPick(1, -1);
    
    //this.xDir = AB.randomPick(SPEED, -SPEED);
    //this.yDir = AB.randomPick(SPEED, -SPEED);
    //this.zDir = AB.randomPick(SPEED, -SPEED);
    
  }
  
  add(scene) {
    scene.add ( this.ball );
  }
 

 
  update() {
    let limit = 500;
     
     if(Math.abs(this.ball.position.x) > limit)
       this.xDir = -this.xDir;

     if(Math.abs(this.ball.position.y) > limit)
        this.yDir = -this.yDir;
        
     //if(Math.abs(this.ball.position.z) > limit)
     //   this.zDir = -this.zDir;

     
     this.ball.position.x += this.xDir;
     this.ball.position.y += this.yDir;
     //this.ball.position.z += this.zDir;
  }
}


var balls = [
new Ball(),
new Ball(),
];

// 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:
    for(let i = 0; i < balls.length; i++) {
        balls[i].add(ABWorld.scene);
    }
};

AB.world.nextStep = function()
{
    for(let i = 0; i < balls.length; i++) {
        balls[i].update();
    }
};