I'll help you create a 3D representation of Earth using HTML, CSS, and JavaScript with Three.js, a popular 3D graphics library. Here's a complete example:
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3D Earth Visualization</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #000;
}
canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
// Scene setup
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Earth texture
const textureLoader = new THREE.TextureLoader();
const earthTexture = textureLoader.load('https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73909/world.topo.bathy.200407.3x5400x2700.png');
const normalMap = textureLoader.load('https://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57730/gebco_08_rev_elev_S4_1deg.png');
// Earth geometry
const geometry = new THREE.SphereGeometry(5, 64, 64);
const material = new THREE.MeshStandardMaterial({
map: earthTexture,
normalMap: normalMap,
metalness: 0.4,
roughness: 0.7
});
const earth = new THREE.Mesh(geometry, material);
scene.add(earth);
// Lighting
const ambientLight = new THREE.AmbientLight(0x404040);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(5, 3, 5);
scene.add(directionalLight);
// Camera positioning
camera.position.z = 15;
// Animation
function animate() {
requestAnimationFrame(animate);
earth.rotation.y += 0.005;
renderer.render(scene, camera);
}
animate();
// Responsive handling
window.addEventListener('resize', () => {
const newWidth = window.innerWidth;
const newHeight = window.innerHeight;
camera.aspect = newWidth / newHeight;
camera.updateProjectionMatrix();
renderer.setSize(newWidth, newHeight);
});
</script>
</body>
</html>
This code does the following:
Uses Three.js library for 3D rendering
Creates a spherical Earth geometry
Applies a realistic Earth texture and normal map
Adds ambient and directional lighting
Implements a slow rotation animation
Includes responsive design for different screen sizes
Key features:
Smooth rotation of the Earth
Realistic texture from NASA imagery
Normal map for terrain details
Responsive design
Notes:
Requires an internet connection to load Three.js and textures
Best viewed in modern browsers
Texture URLs might change, so you may need to update them
To use this, simply save as an HTML file and open in a web browser. The Earth will slowly rotate, giving a nice 3D visualization.