Programming Assignment Unit 6
Programming Assignment Unit 6
>>>html
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
>>>javascript
// Create a scene
const scene = new THREE.Scene();
// Create a camera
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight,
0.1, 1000);
// Create a renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Animation parameters
let moonOrbitRadius = 2;
let moonOrbitAngle = 0;
let moonRotationSpeed = 0.02;
let earthRotationSpeed = 0.01;
// Animation loop
function animate() {
requestAnimationFrame(animate);
animate();
1. Earth and Moon Geometries:
○ The Earth is represented by a sphere with a realistic texture applied using a
TextureLoader.
○ The Moon is a smaller sphere with its own texture applied.
2. Lighting:
○ A point light is positioned to the right to simulate sunlight, casting shadows and
illuminating one side of the Earth and Moon.
3. Rotations:
○ The Earth rotates on its axis to simulate day and night.
○ The Moon rotates on its axis for realism.
4. Moon's Orbit:
○ The Moon orbits around the Earth in a circular path, calculated using sine and
cosine functions.
5. Renderer:
○ The WebGLRenderer is used to display the scene in the browser, and its size
matches the window dimensions.
References:
Textures: