A realistic falling sand physics simulator built with Svelte and Canvas. Experiment with different materials including sand, water, and gas, each with their own unique physics behaviors.
-
Three Material Types:
- Sand - Falls straight down, piles up naturally
- Water - Falls down, flows horizontally, displaces gas
- Gas - Rises upward and spreads randomly
-
Realistic Physics:
- Gravity simulation for solid and liquid materials
- Buoyancy effects (gas rises through liquids)
- Material displacement interactions
- Real-time particle simulation
-
Interactive Controls:
- Click and drag to add materials
- Material selection buttons
- Clear canvas functionality
- Responsive design
Visit the live demo: [Coming Soon]
- Frontend Framework: Svelte + SvelteKit
- Language: TypeScript
- Graphics: HTML5 Canvas
- Physics: Custom vanilla JavaScript engine
- Styling: CSS3 with responsive design
- Node.js (v16 or higher)
- npm, pnpm, or yarn
- Clone the repository:
git clone https://github.com/yourusername/falling_sand_py.git
cd falling_sand_py
- Install dependencies:
npm install
- Start the development server:
npm run dev
- Open your browser and navigate to
http://localhost:5173
To create a production build:
npm run build
Preview the production build:
npm run preview
- Select a Material: Click one of the three material buttons (Sand, Water, Gas)
- Add Materials: Click and drag on the black canvas to add particles
- Watch Physics: Observe how different materials interact with each other
- Clear Canvas: Use the "Clear Canvas" button to reset the simulation
- Falls straight down due to gravity
- Settles diagonally when blocked
- Forms stable piles and slopes
- Falls down like sand but flows horizontally
- Displaces lighter materials (gas)
- Seeks the lowest level (levels out)
- Rises upward (negative gravity)
- Spreads randomly when blocked
- Gets displaced by heavier materials
src/
├── lib/
│ ├── SandCanvas.svelte # Canvas component
│ └── sand-simulation.ts # Physics engine
├── routes/
│ └── +page.svelte # Main page
└── app.html # HTML template
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- More material types (stone, oil, fire)
- Temperature system
- Chemical reactions between materials
- Save/load simulation states
- Performance optimizations
- Mobile touch controls
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by classic falling sand games
- Built with modern web technologies
- Physics simulation optimized for 60fps performance