Table of Contents
Particle Life is just a simple python script. It makes a window and shows different movement of particles, whose rules are defined by us while writing the code. It is a simple python script in which I have implemented OOP.
The python libraries that are used are :-
-
pygame
pip3 install pygame
-
math
-
random
- A
Particle
class is there which takes -- true for running the while loop
- width of screen
- height of screen
- color of screen in rgb in this case -
rgb(0,0,0)
createParticle
function - This renders a particle in the screen with specific color and coordinatesreturnParticle
function - Returns a dict consisting of x,y,color,velocityX,velocityYmanyParticles
function - Returns a list of particles consisting of the above dictionary with random x and y positionscreateParticles
function - Creates all the particles in the list returned above using thecreateParticle
functionmainRule
function - Uses physics and maths formula to attract the particles towards each other and reflect back the particles by using the value ofg
- Formula Used:-
- F = GMm/r^2
- squareroot[(x2-x1)^2 + (y2-y1)^2]
- F = ma
- Important things -
- g is -ve if the particles are attracted
- g is +ve if the particles are repelling each other
- Formula Used:-
-
To render particles two things we need to run -
self.yellowParticles = self.manyParticles(200, self.yellow)
- To get the list of particlesself.createParticles(self.yellowParticles)
- To render the particles, used in the while loop
- To write the mainrules, we need to give 3 arguements - particles list1, particle list2, g
self.mainRule(self.yellowParticles, self.yellowParticles, -0.1)
- Here yellow particles are attracted by each other by a small force of 0.1
You can simulate the particle animation by writing the mainrule, rendering particles and defining colors.
-
Define colors
self.yellow = (255, 255, 0)
- It should be written indef __init__
-
About Rendering particles you can get the information above
-
Write your mainrules as you want in the while loop
This are some of the tests that are done.
The Installation is pretty easy.
- Make a directory in your computer to store the files.
- Go into the directory and clone the git repository
git clone https://github.com/CapedDemon/Particle-life.git
- Open your favourite terminal, and type this commands
pip3 install requirements.txt
Then,
python3 particle.py
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b any-name
) - Commit your Changes (
git commit -m 'Add some advices'
) - Push to the Branch (
git push origin
) - Open a Pull Request
Support me by following me and giving a ✨ to this repo.
MIT LICENSE