A highly customizable non-deterministic particle simulation that uses multithreading and grid hashing for extra performance.
- Particle creation and management
- Gravity and drag effects
- Collision detection and resolution
- Multi-threaded updates for improved performance
- Visualization using Java Swing
- Java Development Kit (JDK) 8 or higher
-
Clone the repository:
git clone https://github.com/cruzfelipee/ParticleSimulator.git cd ParticleSimulator -
Open the project in your preferred IDE.
-
Build the project to resolve dependencies.
You can configure the simulation parameters in the App.java file:
- NUMBER_OF_PARTICLES: Number of particles in the simulation.
- MIN_RADIUS: Minimum radius of the particles.
- MAX_RADIUS: Maximum radius of the particles.
- MS_DELAY: Delay between the spawn of each particle.
- Main: Contains the main application entry point.
- Services: Contains services for handling various aspects of the simulation (e.g., gravity, collisions, boundaries).
- Structures: Contains data structures used in the simulation (e.g., Particle, Vector2, Grid).
- Tools: Contains utility classes (e.g., ParticleDrawer, ParticleHeightComparator).
- App: The entry point of the application. Initializes and runs the simulation.
- Simulator: Manages the simulation, including updating particle positions and velocities.
- BoundariesService: Handles boundary interactions for particles.
- CollisionService: Handles collision detection and resolution between particles.
- DragService: Applies drag force to particles.
- GravityService: Applies gravity force to particles.
- ParticlesService: Manages particle creation and spawning.
- SeparatorService: Ensures particles are not overlapping.
- Particle: Represents a particle in the simulation.
- Vector2: Represents a 2D vector with various vector operations.
- Grid: A spatial grid for efficient neighbor searching.
- ParticleDrawer: A JPanel for drawing particles.
- Inspired by @johnBuffer Physics Engine and @keyframe41 Particle Simulation
NOTE: The algorithm is meant to run at a variable framerate, which can lead to unexpected behaviour and will create a different simulation every time you execute the program.