varearth_cam =newTHREE.PerspectiveCamera(75, aspect_ratio, 1, 1e6);
varcamera = above_cam;
// This will draw what the camera sees onto the screen:
varrenderer =newTHREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// ******** START CODING ON THE NEXT LINE ********
document.body.style.backgroundColor ='black';
varsurface =newTHREE.MeshPhongMaterial({ambient: 0xFFD700});
varstar =newTHREE.SphereGeometry(50, 28, 21);
varsun =newTHREE.Mesh(star, surface);
scene.add(sun);
varambient =newTHREE.AmbientLight(0xffffff);
scene.add(ambient);
varsunlight =newTHREE.PointLight(0xffffff, 5, 1000);
sun.add(sunlight);
varsurface =newTHREE.MeshPhongMaterial({ambient: 0x1a1a1a, color: 0x0000cd});
varplanet =newTHREE.SphereGeometry(20, 20, 15);
varearth =newTHREE.Mesh(planet, surface);
earth.position.set(250, 0, 0);
scene.add(earth);
varsurface =newTHREE.MeshPhongMaterial({ambient: 0x1a1a1a, color: 0xffffff});
varplanet =newTHREE.SphereGeometry(15, 30, 25);
varmoon =newTHREE.Mesh(planet, surface);
varmoon_orbit =newTHREE.Object3D();
earth.add(moon_orbit);
moon_orbit.add(moon);
moon.position.set(0, 100, 0);
moon_orbit.add(earth_cam);
earth_cam.rotation.set(Math.PI/2, 0, 0);
vartime = 0,
speed = 1,
pause = false;
functionanimate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
if(pause)return;
time = time + speed;
Appendix 1. Project Code • 244
Prepared exclusively for Michael Powell report erratum • discuss