Skip to content
On this page

Getting Started


You need to have Java 16 or higher. (Contrary to the Desktop App, you don't need Windows for this.)

Add this to your build.gradle:

repositories {
    maven { url "" }

dependencies {
    implementation "com.github.tom-mohr:particle-life:v0.2.0"

You can now import the framework in Java:

import com.particle_life.*;

Running the Simulation

First, instantiate an Accelerator. Example:

Accelerator accelerator = (a, pos) -> {
    // this is the force function of particle life:
    double rmin = 0.3;
    double dist = pos.length();
    double force;
    if (dist < rmin) {
        force = (dist / rmin - 1);
    } else {
        force = a * (1 - Math.abs(1 + rmin - 2 * dist) / (1 - rmin));
    return pos.mul(force / dist);

Next, instantiate the Physics class and pass the accelerator to the constructor.

Physics physics = new Physics(accelerator);

To run your simulation, you need to repeatedly call Physics.update() to recompute the velocities and positions of the particles.

while (true) {

// call this at the end of your program

Number of Update Threads

Use Physics.preferredNumberOfThreads to control the number of threads that are used in the Physics.update() method.


This is independent of whether you use synchronous or asynchronous updating.

Particle Coordinates

Particles have a position, a velocity and a type. The coordinates of the position are in the range of [-1.0, 1.0]. Therefore you may need to map them to screen coordinates when drawing the particles.

By default, Physics.settings.wrap is true. This allows the particles move and interact across the world's borders. If Physics.settings.wrap is false, they will collide with the world's borders.