A Flutter application that simulates the movement and interaction of particles based on mouse position. Particles are attracted to the mouse or to a calculated point if the mouse is not moving. This project demonstrates the use of Flutter's CustomPainter
for custom drawing and GestureDetector
for handling user interactions.
- Flutter installed on your machine. If you don't have Flutter installed, follow the instructions on the official Flutter website.
-
Clone the repository:
git clone https://github.com/hamed-rezaee/flutter_particle_attraction_simulation.git
-
Install the dependencies:
flutter pub get
-
Run the app:
flutter run
main
: Entry point of the application. Sets up the main widget and handles particle logic.Particle
: A class representing an individual particle.ParticleAnimation
: A stateful widget that manages the particle system and user interactions.ParticlePainter
: A custom painter that renders the particles on the canvas.
You can customize the behavior and appearance of the particles by modifying the following constants in ParticleAnimation:
rows
: Number of rows of particles.cols
: Number of columns of particles.numParticles
: Total number of particles (rows * cols).thickness
: Attraction strength. Increase for stronger attraction.spacing
: Distance between particles.margin
: Margin around the particle grid.color
: Color intensity of the particles.drag
: Damping factor for particle movement.ease
: Ease factor for particle movement.
This project was inspired by https://codepen.io/soulwire/pen/DdGRYG by Justin Windle.
This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.