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;
});
// Star background
const stars = [];
for (let i = 0; i < 200; i++) {
stars.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
size: Math.random() * 2,
brightness: Math.random()
});
}
function drawStars() {
stars.forEach(star => {
ctx.fillStyle = `rgba(255, 255, 255, ${star.brightness})`;
ctx.fillRect(star.x, star.y, star.size, star.size);
});
}
function drawSun() {
// Sun glow
const gradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, 40 * zoom);
gradient.addColorStop(0, '#FFF5B0');
gradient.addColorStop(0.5, '#FFD700');
gradient.addColorStop(1, 'rgba(255, 215, 0, 0)');
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Sun body
ctx.fillStyle = '#FFD700';
ctx.beginPath();
ctx.arc(centerX, centerY, 25 * 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
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();
// Draw Saturn's rings
if (planet.hasRings) {
ctx.strokeStyle = planet.color;
ctx.lineWidth = 3 * zoom;
ctx.beginPath();
ctx.ellipse(x, y, planet.radius * 1.8 * zoom, planet.radius * 0.5 * zoom, 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 animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawStars();
drawSun();
planets.forEach(planet => {
if (!isPaused) {
planet.angle += (planet.speed * 0.001 * speedMultiplier);
}
drawPlanet(planet);
});
requestAnimationFrame(animate);
}
// Controls
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;
}
// Event listeners
zoomSlider.addEventListener('input', (e) => {
zoom = parseFloat(e.target.value);
});
canvas.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
centerX = canvas.width / 2;
centerY = canvas.height / 2;
});
// Mouse drag to pan
let isDragging = false;
let dragStartX, dragStartY;
canvas.addEventListener('mousedown', (e) => {
isDragging = true;
dragStartX = e.clientX - centerX;
dragStartY = e.clientY - centerY;
});
canvas.addEventListener('mousemove', (e) => {
if (isDragging) {
centerX = e.clientX - dragStartX;
centerY = e.clientY - dragStartY;
}
});
canvas.addEventListener('mouseup', () => {
isDragging = false;
});
// Start animation
animate();
</script>
</body>
</html>
This solar system simulation includes:
- All 8 planets with realistic relative orbital speeds
- Interactive controls: pause/resume, speed adjustment, zoom, and orbit toggle
- Mouse interaction: hover over planets to see information, click and drag to pan
- Visual features: glowing sun, planet colors, Saturn's rings, orbit paths, and a starry background
- Smooth animation with proper scaling for visibility
The planets orbit at speeds proportional to their real orbital velocities, though the distances and sizes are scaled for better visualization on screen. You can save this as an HTML file and open it in any modern web browser to see the animated solar system!