<!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</title>
<style>
body, html {
margin: 0;
padding: 0;
overflow: hidden;
height: 100%;
background: #000;
}
canvas {
display: block;
}
</style>
</head>
<body>
<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();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const solarSystem = new THREE.Group();
scene.add(solarSystem);
const sunGeometry = new THREE.SphereGeometry(1, 32, 32);
const sunMaterial = new THREE.MeshBasicMaterial({ color: 0xffff00 });
const sun = new THREE.Mesh(sunGeometry, sunMaterial);
solarSystem.add(sun);
const planetData = [
{ radius: 0.3, distance: 2, color: 0x00ff00 },
{ radius: 0.2, distance: 3, color: 0xff0000 },
{ radius: 0.1, distance: 4, color: 0x0000ff },
{ radius: 0.15, distance: 5, color: 0xffff00 },
{ radius: 0.05, distance: 6, color: 0xffa500 },
{ radius: 0.08, distance: 7, color: 0x800080 },
{ radius: 0.06, distance: 8, color: 0x00ffff }
];
planetData.forEach((data, index) => {
const planetGeometry = new THREE.SphereGeometry(data.radius, 32, 32);
const planetMaterial = new THREE.MeshBasicMaterial({ color: data.color });
const planet = new THREE.Mesh(planetGeometry, planetMaterial);
planet.position.x = data.distance;
solarSystem.add(planet);
});
camera.position.z = 10;
function animate() {
requestAnimationFrame(animate);
solarSystem.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>