I'll create an interactive solar system simulation for you. This HTML file includes the sun and planets with realistic relative sizes, orbital speeds, and distances (scaled for visibility).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Solar System Simulation</title>
<style>
body {
margin: 0;
padding: 0;
background: #000;
overflow: hidden;
font-family: Arial, sans-serif;
}
#canvas {
display: block;
background: radial-gradient(ellipse at center, #1a1a2e 0%, #000 100%);
}
#controls {
position: absolute;
top: 10px;
left: 10px;
color: white;
background: rgba(0, 0, 0, 0.7);
padding: 15px;
border-radius: 5px;
}
#controls button {
margin: 5px;
padding: 5px 10px;
background: #333;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
}
#controls button:hover {
background: #555;
}
#info {
position: absolute;
top: 10px;
right: 10px;
color: white;
background: rgba(0, 0, 0, 0.7);
padding: 15px;
border-radius: 5px;
max-width: 200px;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div id="controls">
<h3>Solar System Controls</h3>
<button onclick="togglePause()">Pause/Resume</button>
<button onclick="resetView()">Reset View</button>
<button onclick="toggleOrbits()">Toggle Orbits</button>
<button onclick="changeSpeed(0.5)">Speed x0.5</button>
<button onclick="changeSpeed(2)">Speed x2</button>
<div>
<label>Zoom: <input type="range" id="zoom" min="0.1" max="3" step="0.1" value="1"></label>
</div>
</div>
<div id="info">
<h3>Planet Info</h3>
<p id="planetInfo">Hover over a planet to see details</p>
</div>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const zoomSlider = document.getElementById('zoom');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let centerX = canvas.width / 2;
let centerY = canvas.height / 2;
let isPaused = false;
let showOrbits = true;
let speedMultiplier = 1;
let zoom = 1;
let mouseX = 0;
let mouseY = 0;
// Planet data (scaled for visibility)
const planets = [
{ name: 'Mercury', radius: 4, distance: 60, speed: 4.74, color: '#8C7853', realRadius: 2439.7 },
{ name: 'Venus', radius: 8, distance: 90, speed: 3.5, color: '#FFC649', realRadius: 6051.8 },
{ name: 'Earth', radius: 8, distance: 120, speed: 2.98, color: '#4169E1', realRadius: 6371 },
{ name: 'Mars', radius: 5, distance: 160, speed: 2.41, color: '#CD5C5C', realRadius: 3389.5 },
{ name: 'Jupiter', radius: 20, distance: 280, speed: 1.31, color: '#DAA520', realRadius: 69911 },
{ name: 'Saturn', radius: 17, distance: 380, speed: 0.97, color: '#F4A460', realRadius: 58232, hasRings: true },
{ name: 'Uranus', radius: 12, distance: 500, speed: 0.68, color: '#4FD0E0', realRadius: 25362 },
{ name: 'Neptune', radius: 11, distance: 600, speed: 0.54, color: '#4169E1', realRadius: 24622 }
];
// Initialize planet angles
planets.forEach(planet => {
planet.angle = Math.random() * Math.PI * 2;
});
// Mouse tracking
canvas.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
// Zoom control
zoomSlider.addEventListener('input', (e) => {
zoom = parseFloat(e.target.value);
});
function drawSun() {
// Sun glow effect
const gradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, 30 * zoom);
gradient.addColorStop(0, '#FFF5B0');
gradient.addColorStop(0.3, '#FFD700');
gradient.addColorStop(1, 'rgba(255, 215, 0, 0)');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(centerX, centerY, 30 * zoom, 0, Math.PI * 2);
ctx.fill();
// Sun core
ctx.fillStyle = '#FFD700';
ctx.beginPath();
ctx.arc(centerX, centerY, 20 * zoom, 0, Math.PI * 2);
ctx.fill();
}
function drawPlanet(planet) {
const x = centerX + Math.cos(planet.angle) * planet.distance * zoom;
const y = centerY + Math.sin(planet.angle) * planet.distance * zoom;
// Draw orbit path
if (showOrbits) {
ctx.strokeStyle = 'rgba(255, 255, 255, 0.2)';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.arc(centerX, centerY, planet.distance * zoom, 0, Math.PI * 2);
ctx.stroke();
}
// Draw planet
ctx.fillStyle = planet.color;
ctx.beginPath();
ctx.arc(x, y, planet.radius * zoom, 0, Math.PI * 2);
ctx.fill();
// Add shading
const gradient = ctx.createRadialGradient(
x - planet.radius * zoom * 0.3,
y - planet.radius * zoom * 0.3,
0,
x,
y,
planet.radius * zoom
);
gradient.addColorStop(0, 'rgba(255, 255, 255, 0.3)');
gradient.addColorStop(1, 'rgba(0, 0, 0, 0.3)');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(x, y, planet.radius * zoom, 0, Math.PI * 2);
ctx.fill();
// Draw Saturn's rings
if (planet.hasRings) {
ctx.strokeStyle = planet.color;
ctx.lineWidth = 3 * zoom;
ctx.beginPath();
ctx.ellipse(x, y, planet.radius * zoom * 1.8, planet.radius * zoom * 0.7, 0, 0, Math.PI * 2);
ctx.stroke();
}
// Check hover
const dist = Math.sqrt((mouseX - x) ** 2 + (mouseY - y) ** 2);
if (dist < planet.radius * zoom) {
document.getElementById('planetInfo').innerHTML = `
<strong>${planet.name}</strong><br>
Radius: ${planet.realRadius.toLocaleString()} km<br>
Orbital Speed: ${planet.speed} km/s
`;
}
}
function drawStars() {
ctx.fillStyle = 'white';
for (let i = 0; i < 200; i++) {
const x = Math.random() * canvas.width;
const y = Math.random() * canvas.height;
const size = Math.random() * 2;
ctx.beginPath();
ctx.arc(x, y, size, 0, Math.PI * 2);
ctx.fill();
}
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw background stars (static)
if (!isPaused) {
ctx.save();
ctx.globalAlpha = 0.1;
drawStars();
ctx.restore();
}
drawSun();
// Update and draw planets
planets.forEach(planet => {
if (!isPaused) {
planet.angle += (planet.speed * 0.001 * speedMultiplier);
}
drawPlanet(planet);
});
requestAnimationFrame(animate);
}
// Control functions
function togglePause() {
isPaused = !isPaused;
}
function resetView() {
zoom = 1;
zoomSlider.value = 1;
speedMultiplier = 1;
centerX = canvas.width / 2;
centerY = canvas.height / 2;
}
function toggleOrbits() {
showOrbits = !showOrbits;
}
function changeSpeed(factor) {
speedMultiplier *= factor;
}
// Handle window resize
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
centerX = canvas.width / 2;
centerY = canvas.height / 2;
});
// Start animation
animate();
</script>
</body>
</html>
This solar system simulation features:
- Realistic orbital mechanics: Each planet orbits at a speed proportional to its real orbital velocity
- Interactive controls: Pause/resume, zoom, speed adjustment, and orbit path toggling
- Visual effects: Glowing sun, planet shading, Saturn's rings, and a starfield background
- Planet information: Hover over any planet to see its details
- Responsive design: Automatically adjusts to window size
The simulation uses scaled distances and sizes to make everything visible on screen while maintaining relative proportions. You can save this as an HTML file and open it in any modern web browser to see the animated solar system.