This project is a simple sand simulation built with Flutter, where users can "pour" sand particles that fall and settle, forming a natural, mountain-like sediment pattern. The particles fall under simulated gravity and accumulate at the bottom, creating an interactive and visually appealing effect.
The project has two main components:
-
SandSimulation Widget
The
SandSimulationwidget is the main simulation screen, where sand particles are animated as they fall and settle. Users can add sand particles by dragging on the screen, creating an interactive and dynamic experience. -
SandPainter Widget
The
SandPainterwidget is a custom painter that renders each cell in the sand grid according to its state. This widget is responsible for drawing each particle and updating the colors to simulate sand particles as they stack and settle.
- Dynamic Particle Simulation: Particles fall to the bottom and stack up naturally, simulating the look and behavior of sand piling up.
- Interactive Input: Users can drag across the screen to add new sand particles.
- Reset Functionality: A button in the app bar allows users to clear the simulation and reset the grid.
This project was inspired by a YouTube video tutorial by The Coding Train, which explained the core mechanics of a sand simulation. In the video, The Coding Train also provided a JavaScript example of the sand simulation, and this project recreates that simulation using Flutter.
The simulation divides the screen into a grid, where each cell can either be empty or filled with a particle. The particle movement is based on simple physics rules:
- Particles fall if there is empty space below them.
- If there is no space directly below, they will try to settle to the sides.
- Particles "pile up" naturally, simulating a sand-like effect.
This project was built just for fun, and there's still plenty of room for optimization and performance improvements. Future versions could aim to:
- Improve the simulation speed, especially for larger grids.
- Refine particle movement for smoother transitions.
- Enhance visual effects with shading and more granular physics.
