VSCode Space 🌌

An interactive N-Body gravity simulation right in your VS Code explorer. Watch celestial bodies orbit, collide, and merge in real-time using the Barnes-Hut algorithm!

✨ Features
🚀 Real-Time Physics Simulation
- Barnes-Hut Algorithm — Efficient O(n log n) gravitational calculations
- Collision Detection — Bodies merge on contact with momentum conservation
- Stable Orbits — Leapfrog integration for accurate orbital mechanics
🎨 Visual Effects
- Smooth Trails — Gradient trails that fade from oldest to newest points
- Starfield Background — Thousands of background stars (performance optimized)
- Color-Coded Bodies — Visual distinction based on mass and type
🌍 Built-in Presets
| Preset |
Description |
| Solar System |
Stable 8-planet system with realistic orbits |
| Binary Stars |
Two massive stars in gravitational dance |
| Three Body |
Classic chaotic three-body problem |
| Galaxy |
Spiral galaxy with rotation effect |
| Collision |
High-energy collision scenarios |
| Ring |
Saturn-like ring formation |
| Cluster |
1000-body galaxy simulation |
🎮 Interactive Controls
- ◀️ Slow Down — Decrease time scale (-1x)
- ⏸️/▶️ Pause/Play — Toggle simulation
- ▶️ Speed Up — Increase time scale (+1x)
- ➕ Spawn — Add new celestial bodies
Mouse
- Click + Drag — Pan the camera
- Scroll Wheel — Zoom in/out
- Click (with body selected) — Spawn body at position
Body Types
Spawn different celestial objects via the + menu:
| Type | Description |
|------|-------------|
| 🪨 Asteroid | Tiny, minimal gravitational effect |
| 🪐 Planet | Small, orbiting body |
| ⭐ Star | Medium mass, bright coloring |
| 🔴 Giant | Large, heavy body |
| ⚫ Black Hole | Massive, with signature red border |
📦 Installation
From VS Code Marketplace
- Open VS Code
- Go to Extensions (
Cmd+Shift+X / Ctrl+Shift+X)
- Search for "VSCode Space"
- Click Install
From VSIX
- Download the
.vsix file from Releases
- In VS Code, open Command Palette (
Cmd+Shift+P / Ctrl+Shift+P)
- Run "Extensions: Install from VSIX..."
- Select the downloaded file
🚀 Usage
- Open Explorer — The simulation appears in a panel in the Explorer sidebar
- Choose a Preset — Click the ⋯ menu and select a preset
- Watch & Interact — Pan, zoom, and spawn new bodies!
Commands
All commands are available via Command Palette (Cmd+Shift+P / Ctrl+Shift+P):
| Command |
Description |
Space: Pause |
Pause the simulation |
Space: Play |
Resume the simulation |
Space: Reset Simulation |
Reset to initial state |
Space: Speed Up (+1x) |
Increase time scale |
Space: Slow Down (-1x) |
Decrease time scale |
Space: Preset: Solar System |
Load solar system preset |
Space: Preset: Binary Stars |
Load binary stars preset |
Space: Preset: Three Body |
Load three-body preset |
Space: Preset: Galaxy |
Load galaxy preset |
Space: Preset: Collision |
Load collision preset |
Space: Preset: Ring |
Load ring preset |
Space: Preset: Cluster |
Load 1000-body cluster |
Space: Spawn Body |
Open spawn menu |
🔧 Technical Details
Physics Engine
- Algorithm: Barnes-Hut with θ = 0.5 for force approximation
- Integration: Leapfrog method for energy conservation
- Collision: Inelastic merging with mass and momentum conservation
- QuadTree spatial partitioning
- Circular buffer for trail storage
- View frustum culling for off-screen bodies
- Adaptive trail point decimation
- Separate canvas layers (static stars, dynamic simulation)
- Background stars update only on camera movement
Requirements
- VS Code 1.85.0 or higher
- No additional dependencies required
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature)
- Commit your changes (
git commit -m 'Add some AmazingFeature')
- Push to the branch (
git push origin feature/AmazingFeature)
- Open a Pull Request
📄 License
This project is licensed under the MIT License — see the LICENSE file for details.
👨💻 Author
Keshav Madhav
🌐 Space Simulator (Browser Version)
Want a more expansive, full-featured gravitational sandbox? Check out the companion browser-based simulator:
| Feature |
VSCode Space |
Browser Simulator |
| Body Count |
Ideally 100 |
Ideally 20,000+ |
| Custom Spawning |
Preset types |
Full radius/density/color control |
| Camera |
Pan & zoom |
Follow body, center-of-mass tracking |
| Controls |
Mouse + toolbar |
Mouse + 15+ keyboard shortcuts |
| Physics Tweaks |
Time scale |
Time scale, collision toggle, velocity units |
| Visualizations |
Trails, starfield |
Trails, velocity vectors, labels, FPS overlay |
| Presets |
7 presets |
6+ presets including deterministic tests |
| Performance |
Optimized for sidebar |
Designed for large-N scaling |
Browser Simulator Highlights:
- 🔬 Scientific sandbox — Experiment with orbital mechanics, three-body chaos, and galaxy formation
- ⚡ Performance-focused — Roadmap includes Barnes-Hut, Web Workers, and WebGL acceleration
- 🎛️ Deep customization — Adjust density, radius, color for each body type
- 📊 Real-time metrics — Velocity vectors, FPS display, unit switching (m/s ↔ km/s)
- 🎹 Keyboard shortcuts —
WASD pan, C follow camera, T/K/G spawn presets, and more
Perfect for when you want to dive deeper into gravitational physics without leaving your browser!
🙏 Acknowledgments
- Inspired by Space-Simulation-HTML-CSS-JS
- Barnes-Hut algorithm for efficient N-body simulation
- VS Code Extension API for seamless integration
Enjoy exploring the cosmos from your code editor! 🌟
⭐ Star this repo if you find it useful!