A particle simulation written in C. Particle Life explores the concept of emergence, where complex structures arise from simple rules. Inspired by Tom Mohr's video on Particle Life simulations.
The provided executable may not work on your architecture. If this is the case, you will need to compile the program in the provided build folder. We recommend using Conan + CMake, config files for which are provided.
./build/plife simulation.txt
Modify simulation.txt
to configure simulation properties. Ensure that if you specify n
quantities, the attraction matrix is n x n
. We recommend a viscosity of 0.4
and a repulsion strength of 4.0
based on testing.
Epochs
: Number of simulation frames to renderQuantities
: Number of each particle type in simulationAttraction
: Attraction matrix, in same order as quantities are definedViscosity
: Slows particles down as they move to prevent chaosRadius
: How close particles need to be to interactRepulsionStrength
: How much particles push back on eachother when getting too close (to minimize particle overlap)
Example simulation.txt
:
#Epochs
1000
#Quantities
50 50
#Attraction
0.5 -0.2
-0.3 0.8
#Viscosity
0.4
#Radius
50
#RepulsionStrength
4.0
The runner.py
script automates the creation of simulation.txt
with customizable attributes and runs the PLife simulation. Currently epochs, viscocity, radius, and repulsion strength cannot be modified with flags directly. If you wish to modify these, do so in the runner.py
script directly. runner.py
only supports creation of uniform particle quantities.
Note that the plife
executable is still required to use the runner.
python3 runner.py -s SIZE -n NUMBER
-s SIZE
: Number of particle types (required).-n NUMBER
: Number of particles per type (required).
Example:
python3 runner.py -s 5 -n 200
-a
,--assortativity
:high
orlow
.-d
,--degree
: Degree distribution (integer between 1 and size of matrix-s
).-c
,--clustering
: Clustering coefficient (0 to 1).-k
,--skew-symmetry
:high
,medium
, orlow
.-r
,--reciprocity
: Reciprocity level (0 to 1).-p
,--sparsity
: Proportion of possible edges (0 to 1).
python3 runner.py -s 5 -n 200 -a high
python3 runner.py -s 5 -n 200 -p 0.2
python3 runner.py -s 5 -n 200 -k high -r 0.7
You can combine any number of attributes. However, some attributes will contradict each other, so note the following conditions.
- Sparsity and Degree Distribution: If both are specified, degree distribution takes precedence.
- Reciprocity and Skew Symmetry: Reciprocity is applied after skew symmetry and can override it.
- Modify
build/simulation.txt
to manually adjust particles, the attraction matrix, or epochs. - The
simulation.txt
file can be renamed; specify the correct filename when running the simulation. However,runner.py
usesbuild/simulation.txt
. - If you wish to modify the particle simulation code (
src/main.c
), you must set up your Conan environment or link dependencies manually. Conan is a package manager for C/C++ and is used in this project to resolve the SDL2 and ZLIB dependencies. Please refer to the Conan official documentation.