An interactive Pygame visualization where particles behave like magnetic objects, dynamically attracting toward the mouse cursor in real time.
Magnet Particles Simulation is an interactive visualization built using Python and Pygame, where hundreds of particles move dynamically toward the mouse cursor, creating a magnetic-field-like effect.
This project demonstrates basic physics concepts, vector math, and object-oriented programming in a visually engaging way.
- Interactive magnetic attraction using mouse movement
- 300 lightweight particles rendered in real time
- Smooth motion using distance-based force calculation
- Object-Oriented Programming (OOP) approach
- Clean and minimal visual design
- Python 3
- Pygame
mathandrandommodules
Python 3
Pygame (pip install pygame)
Run the Project python magnet.py
Each particle calculates its distance from the mouse cursor.
A magnetic force inversely proportional to the distance is applied.
Particles move smoothly toward the cursor, creating a magnetic field effect.
The closer the particle is, the stronger the attraction.
This project was created as a learning experiment to explore interactive graphics and particle simulations using Pygame.