Certainly! Below is an HTML file that uses Three.js to create a visualization of a moose in a forest with an alien spaceship hovering above, lifting the moose with a beam. This example uses basic shapes to represent the moose, forest, and spaceship for simplicity.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Moose Lift-off</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.174.0/three.tsl.js"></script>
</head>
<body>
<script>
let scene, camera, renderer;
let moose, spaceship, beam;
let clock = new THREE.Clock();
init();
animate();
function init() {
scene = new THREE.Scene();
scene.background = new THREE.Color(0x87CEEB); // Sky blue
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Forest floor
const floorGeometry = new THREE.PlaneGeometry(20, 20);
const floorMaterial = new THREE.MeshBasicMaterial({color: 0x228B22, side: THREE.DoubleSide});
const floor = new THREE.Mesh(floorGeometry, floorMaterial);
floor.rotation.x = -Math.PI / 2;
scene.add(floor);
// Moose
const mooseGeometry = new THREE.BoxGeometry(1, 1, 1);
const mooseMaterial = new THREE.MeshBasicMaterial({color: 0x8B4513});
moose = new THREE.Mesh(mooseGeometry, mooseMaterial);
moose.position.y = 0.5;
scene.add(moose);
// Spaceship
const spaceshipGeometry = new THREE.CylinderGeometry(0.5, 0.5, 1, 32);
const spaceshipMaterial = new THREE.MeshBasicMaterial({color: 0x00FFFF});
spaceship = new THREE.Mesh(spaceshipGeometry, spaceshipMaterial);
spaceship.position.y = 3;
scene.add(spaceship);
// Beam
const beamGeometry = new THREE.CylinderGeometry(0.05, 0.05, 2, 32);
const beamMaterial = new THREE.MeshBasicMaterial({color: 0x00FF00});
beam = new THREE.Mesh(beamGeometry, beamMaterial);
beam.position.y = 1.5;
scene.add(beam);
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
const delta = clock.getDelta();
// Move the beam and moose up
if (moose.position.y < 2) {
moose.position.y += delta;
beam.position.y = (moose.position.y + 0.5) / 2;
}
renderer.render(scene, camera);
}
</script>
</body>
</html>
Explanation:
-
Scene Setup:
- A
scene is created to hold all objects.
- A
camera is positioned to view the scene.
- A
renderer is set up to render the scene to the canvas.
-
Forest Floor:
- A plane geometry represents the forest floor.
-
Moose:
- A simple box geometry represents the moose.
-
Spaceship:
- A cylinder geometry represents the alien spaceship.
-
Beam:
- Another cylinder geometry represents the beam lifting the moose.
-
Animation:
- The
animate function updates the positions of the moose and beam over time, creating the effect of the moose being lifted.
This code provides a basic yet visually cool representation using Three.js. For a more detailed and realistic visualization, you would need more complex models and textures.