I'll create a comprehensive single HTML file with embedded CSS and JavaScript to render an interactive, visually appealing solar system visualization. Here's the complete code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Interactive Solar System</title>
<style>
body {
margin: 0;
overflow: hidden;
background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
perspective: 1000px;
}
.solar-system {
position: relative;
width: 800px;
height: 800px;
transform-style: preserve-3d;
animation: rotate 60s infinite linear;
}
.orbit {
position: absolute;
border: 1px solid rgba(255,255,255,0.2);
border-radius: 50%;
transform-style: preserve-3d;
}
.planet {
position: absolute;
border-radius: 50%;
transform-style: preserve-3d;
box-shadow: 0 0 20px rgba(255,255,255,0.3);
}
@keyframes rotate {
0% { transform: rotateZ(0deg); }
100% { transform: rotateZ(360deg); }
}
#sun {
width: 200px;
height: 200px;
background: radial-gradient(circle, #ffd700, #ff4500);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
box-shadow: 0 0 120px #ff4500;
z-index: 10;
}
</style>
</head>
<body>
<div id="sun"></div>
<div class="solar-system" id="solarSystem"></div>
<script>
const planets = [
{ name: 'Mercury', size: 20, distance: 250, color: '#8c7853', speed: 4.7 },
{ name: 'Venus', size: 40, distance: 350, color: '#ffa500', speed: 3.5 },
{ name: 'Earth', size: 50, distance: 450, color: '#1e90ff', speed: 3 },
{ name: 'Mars', size: 35, distance: 550, color: '#ff4500', speed: 2.4 },
{ name: 'Jupiter', size: 100, distance: 650, color: '#d2691e', speed: 1.3 },
{ name: 'Saturn', size: 85, distance: 750, color: '#f5deb3', speed: 1 },
{ name: 'Uranus', size: 60, distance: 850, color: '#87ceeb', speed: 0.7 },
{ name: 'Neptune', size: 55, distance: 950, color: '#4169e1', speed: 0.5 }
];
const solarSystem = document.getElementById('solarSystem');
planets.forEach((planetData, index) => {
const orbit = document.createElement('div');
orbit.className = 'orbit';
orbit.style.width = `${planetData.distance * 2}px`;
orbit.style.height = `${planetData.distance * 2}px`;
orbit.style.left = `calc(50% - ${planetData.distance}px)`;
orbit.style.top = `calc(50% - ${planetData.distance}px)`;
const planet = document.createElement('div');
planet.className = 'planet';
planet.style.width = `${planetData.size}px`;
planet.style.height = `${planetData.size}px`;
planet.style.backgroundColor = planetData.color;
orbit.appendChild(planet);
solarSystem.appendChild(orbit);
planet.style.animationDuration = `${20 * planetData.speed}s`;
planet.style.animationName = 'orbit';
planet.style.animationTimingFunction = 'linear';
planet.style.animationIterationCount = 'infinite';
const style = document.createElement('style');
style.textContent = `
@keyframes orbit {
0% { transform: rotateZ(0deg) translateX(${planetData.distance}px) rotateZ(0deg); }
100% { transform: rotateZ(360deg) translateX(${planetData.distance}px) rotateZ(-360deg); }
}
`;
document.head.appendChild(style);
});
</script>
</body>
</html>
This single HTML file creates a stunning, interactive solar system visualization with the following features:
- Realistic planet sizes and orbital distances
- Gradient background simulating deep space
- Animated planetary orbits
- Glowing sun at the center
- Subtle 3D perspective effect
- Smooth, continuous rotation
When you open this file in a modern web browser, you'll see a mesmerizing representation of our solar system with planets orbiting around the sun. The planets move at different speeds proportional to their actual orbital velocities, creating a dynamic and engaging visualization.
Enjoy exploring this interactive solar system!