A system that can simulate the collision between many small particles following the law of physics about elastic collision.
This project was created in order to help me learn more about the use of PriorityQueue data structure as well as Java Swing library to build GUI application.
Using event-driven programming, the system was constructed base on the events that can happen during the simulation. The order of the event will base on the time that the event occur.
In order to get the earliest (smallest) event that will happen next, we use the PriorityQueue to achieve O(logN) performance.
This project was built with:
- Java Swing: used to build a class dedicated to draw different shapes as well as handle animation on the canvas.
Everything you need is to install Java 11 (or above) to run the system.
1. Compile the source code
To compile the code, make sure you are in the directory that contains all the source code and then simply type the following command to the terminal:
~$ javac *.java
2. Run the class file
After compiling the code, all you need to do is to run the generated Simulator class file. This can be done by using the following command:
~$ java Simulator <number_of_particles> <simulation_time_limit>
You will need to give the program 2 arguments. The first argument will be the number of particles involving in the simulation, depends on your hardward resource this could vary from 10 to 50 (or above). The second argument will be the time limit for the simulation, after this period of time is exceeded, the simulation will stop.
3. Screenshot
This is how the simulation will look like:
MIT © KhoaNam225