<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Solar System Animation</title>
<style>
body {
margin: 0;
overflow: hidden;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="solarSystem"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('solarSystem') });
renderer.setSize(window.innerWidth, window.innerHeight);
const sunGeometry = new THREE.SphereGeometry(1, 32, 32);
const sunMaterial = new THREE.MeshBasicMaterial({ color: 0xffff00 });
const sun = new THREE.Mesh(sunGeometry, sunMaterial);
scene.add(sun);
const planets = [];
const planetData = [
{ size: 0.1, distance: 2, color: 0xaaaaaa, speed: 0.01 },
{ size: 0.2, distance: 3, color: 0xff0000, speed: 0.008 },
{ size: 0.15, distance: 4, color: 0x00ff00, speed: 0.006 },
{ size: 0.25, distance: 5, color: 0x0000ff, speed: 0.004 }
];
planetData.forEach(data => {
const geometry = new THREE.SphereGeometry(data.size, 32, 32);
const material = new THREE.MeshBasicMaterial({ color: data.color });
const planet = new THREE.Mesh(geometry, material);
planets.push({ mesh: planet, distance: data.distance, speed: data.speed, angle: 0 });
scene.add(planet);
});
camera.position.z = 10;
function animate() {
requestAnimationFrame(animate);
sun.rotation.y += 0.01;
planets.forEach(planet => {
planet.angle += planet.speed;
planet.mesh.position.x = Math.cos(planet.angle) * planet.distance;
planet.mesh.position.z = Math.sin(planet.angle) * planet.distance;
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>