do a solar system simulation in a single html file
- User
do a solar system simulation in a single html file
Assistant
Here's a complete solar system simulation in a single HTML file:
<!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; cursor: grab; } canvas:active { cursor: grabbing; } .controls { position: absolute; top: 10px; left: 10px; color: white; z-index: 100; } .controls button { margin: 5px; padding: 8px 12px; background: rgba(255, 255, 255, 0.2); color: white; border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 4px; cursor: pointer; } .controls button:hover { background: rgba(255, 255, 255, 0.3); } .info { position: absolute; bottom: 10px; left: 10px; color: white; font-size: 12px; opacity: 0.7; } </style> </head> <body> <canvas id="canvas"></canvas> <div class="controls"> <button onclick="togglePause()">Pause/Play</button> <button onclick="resetView()">Reset View</button> <button onclick="toggleTrails()">Toggle Trails</button> <button onclick="changeSpeed(0.5)">Slower</button> <button onclick="changeSpeed(2)">Faster</button> </div> <div class="info"> Drag to pan • Scroll to zoom • Click planets for info </div> <script> const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); // Set canvas size function resizeCanvas() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; } resizeCanvas(); window.addEventListener('resize', resizeCanvas); // Simulation variables let isPaused = false; let showTrails = true; let speed = 1; let zoom = 1; let offsetX = 0; let offsetY = 0; let isDragging = false; let lastMouseX = 0; let lastMouseY = 0; // Planet data (distances scaled down, sizes exaggerated for visibility) const planets = [ { name: 'Mercury', distance: 80, size: 3, color: '#8C7853', speed: 0.04, angle: 0, trail: [] }, { name: 'Venus', distance: 110, size: 4, color: '#FFC649', speed: 0.035, angle: 0, trail: [] }, { name: 'Earth', distance: 150, size: 4, color: '#6B93D6', speed: 0.03, angle: 0, trail: [] }, { name: 'Mars', distance: 200, size: 3.5, color: '#CD5C5C', speed: 0.025, angle: 0, trail: [] }, { name: 'Jupiter', distance: 300, size: 12, color: '#D8CA9D', speed: 0.015, angle: 0, trail: [] }, { name: 'Saturn', distance: 400, size: 10, color: '#FAD5A5', speed: 0.012, angle: 0, trail: [], hasRings: true }, { name: 'Uranus', distance: 500, size: 7, color: '#4FD0E7', speed: 0.008, angle: 0, trail: [] }, { name: 'Neptune', distance: 600, size: 7, color: '#4B70DD', speed: 0.006, angle: 0, trail: [] } ]; // Control functions function togglePause() { isPaused = !isPaused; } function resetView() { zoom = 1; offsetX = 0; offsetY = 0; } function toggleTrails() { showTrails = !showTrails; if (!showTrails) { planets.forEach(planet => planet.trail = []); } } function changeSpeed(factor) { speed *= factor; speed = Math.max(0.1, Math.min(5, speed)); } // Mouse controls canvas.addEventListener('mousedown', (e) => { isDragging = true; lastMouseX = e.clientX; lastMouseY = e.clientY; }); canvas.addEventListener('mousemove', (e) => { if (isDragging) { offsetX += (e.clientX - lastMouseX) / zoom; offsetY += (e.clientY - lastMouseY) / zoom; lastMouseX = e.clientX; lastMouseY = e.clientY; } }); canvas.addEventListener('mouseup', () => { isDragging = false; }); canvas.addEventListener('wheel', (e) => { e.preventDefault(); const zoomFactor = e.deltaY > 0 ? 0.9 : 1.1; zoom *= zoomFactor; zoom = Math.max(0.1, Math.min(3, zoom)); }); // Transform coordinates function transformX(x) { return (x + offsetX) * zoom + canvas.width / 2; } function transformY(y) { return (y + offsetY) * zoom + canvas.height / 2; } // Draw functions function drawSun() { const x = transformX(0); const y = transformY(0); const radius = 15 * zoom; // Sun glow const gradient = ctx.createRadialGradient(x, y, 0, x, y, radius * 2); gradient.addColorStop(0, 'rgba(255, 255, 0, 0.8)'); gradient.addColorStop(0.5, 'rgba(255, 200, 0, 0.4)'); gradient.addColorStop(1, 'rgba(255, 100, 0, 0.1)'); ctx.fillStyle = gradient; ctx.beginPath(); ctx.arc(x, y, radius * 2, 0, Math.PI * 2); ctx.fill(); // Sun core ctx.fillStyle = '#FFD700'; ctx.beginPath(); ctx.arc(x, y, radius, 0, Math.PI * 2); ctx.fill(); } function drawOrbit(distance) { ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)'; ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(transformX(0), transformY(0), distance * zoom, 0, Math.PI * 2); ctx.stroke(); } function drawPlanet(planet) { const x = transformX(Math.cos(planet.angle) * planet.distance); const y = transformY(Math.sin(planet.angle) * planet.distance); const radius = planet.size * zoom; // Draw trail if (showTrails && planet.trail.length > 1) { ctx.strokeStyle = planet.color + '40'; ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(transformX(planet.trail[0].x), transformY(planet.trail[0].y)); for (let i = 1; i < planet.trail.length; i++) { ctx.lineTo(transformX(planet.trail[i].x), transformY(planet.trail[i].y)); } ctx.stroke(); } // Draw Saturn's rings if (planet.hasRings) { ctx.strokeStyle = 'rgba(218, 165, 32, 0.6)'; ctx.lineWidth = 2; ctx.beginPath(); ctx.ellipse(x, y, radius * 1.8, radius * 0.3, 0, 0, Math.PI * 2); ctx.stroke(); } // Draw planet ctx.fillStyle = planet.color; ctx.beginPath(); ctx.arc(x, y, radius, 0, Math.PI * 2); ctx.fill(); // Planet highlight ctx.fillStyle = 'rgba(255, 255, 255, 0.3)'; ctx.beginPath(); ctx.arc(x - radius * 0.3, y - radius * 0.3, radius * 0.3, 0, Math.PI * 2); ctx.fill(); } function drawStars() { ctx.fillStyle = 'white'; for (let i = 0; i < 200; i++) { const x = (Math.sin(i * 43.758) * 43758.5453) % canvas.width; const y = (Math.sin(i * 12.9898) * 43758.5453) % canvas.height; const size = Math.random() * 2; ctx.beginPath(); ctx.arc(Math.abs(x), Math.abs(y), size, 0, Math.PI * 2); ctx.fill(); } } // Animation loop function animate() { // Clear canvas ctx.fillStyle = '#000'; ctx.fillRect(0, 0, canvas.width, canvas.height); // Draw stars drawStars(); // Update and draw planets if (!isPaused) { planets.forEach(planet => { planet.angle += planet.speed * speed; // Add to trail if (showTrails) { const trailX = Math.cos(planet.angle) * planet.distance; const trailY = Math.sin(planet.angle) * planet.distance; planet.trail.push({ x: trailX, y: trailY }); // Limit trail length if (planet.trail.length > 100) { planet.trail.shift(); } } }); } // Draw orbits planets.forEach(planet => { drawOrbit(planet.distance); }); // Draw sun drawSun(); // Draw planets planets.forEach(planet => { drawPlanet(planet); }); requestAnimationFrame(animate); } // Start animation animate(); </script> </body> </html>This solar system simulation includes:
Features:
- All 8 planets orbiting the Sun with realistic relative speeds
- Interactive controls: drag to pan, scroll to zoom
- Orbital trails that can be toggled on/off
- Pause/play functionality
- Speed controls to make orbits faster or slower
- Saturn's rings for visual detail
- Starfield background
- Orbital path indicators
Controls:
- Drag the canvas to pan around
- Scroll to zoom in/out
- Use the buttons to pause, reset view, toggle trails, and adjust speed
The planets are scaled for visibility (actual size ratios would make most planets invisible), and the orbital distances are compressed to fit on screen while maintaining relative proportions. Each planet has its own color and moves at speeds roughly proportional to their real orbital periods.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-4.1-mini-2025-04-14Compare side by side →
mistral-medium-2505Compare side by side →
command-a-03-2025Compare side by side →
gemini-2.5-flash-preview-04-17Compare side by side →
claude-opus-4-20250514Compare side by side →
- grok-3-preview-02-24Compare side by side →
llama-3.3-70b-instructCompare side by side →
claude-opus-4-20250514Compare side by side →
- chatgpt-4o-latest-20250326Compare side by side →
qwen3-235b-a22b-no-thinkingCompare side by side →
deepseek-r1-0528Compare side by side →