A particle physics simulation written in Python. Particles interact via contact forces and are visualized using Tkinter.
All dependencies are Python standard library modules. The only system-level requirement is Tkinter (python3-tk), used for optional visualization. No third-party pip packages are needed.
- Docker installed and running on your machine.
From the root of the repository (the directory containing the Dockerfile), run:
docker build -t particle-sim .This will:
- Pull the
python:3-slimbase image. - Install the
python3-tkandtk-devsystem packages required by the graphics module. - Copy all project files into the container under
/app.
Run the simulation with the default settings (20 particles, 10,000 steps, no visualization):
docker run --rm particle-simThe simulation accepts several flags that can be passed after the image name:
| Flag | Description |
|---|---|
-n <num> |
Number of particles to simulate (default: 20) |
-s <num> |
Number of timesteps to run (default: 10000) |
-dt <num> |
Length of each timestep (default: 0.00005) |
-v / -g |
Enable visualization (requires a display) |
-u <num> |
Update visualization every <num> steps |
-e |
Normalize total energy each timestep |
Example — simulate 50 particles for 5,000 steps:
docker run --rm particle-sim python verlet.py -n 50 -s 5000The simulation can render a live Tkinter window while running inside Docker. Because Tkinter relies on an X11 display server, you must forward your host's X11 socket into the container. The exact command differs by operating system.
Linux
# Allow Docker to connect to your local X server
xhost +local:docker
docker run --rm \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
particle-sim python verlet.py -n 50 -s 1000 -v
# Revoke the access grant when done (optional but recommended)
xhost -local:dockermacOS (requires XQuartz)
- Install and launch XQuartz.
- In XQuartz → Preferences → Security, enable "Allow connections from network clients" and restart XQuartz.
- Run:
xhost +localhost
docker run --rm \
-e DISPLAY=host.docker.internal:0 \
particle-sim python verlet.py -n 50 -s 1000 -vWindows (requires an X server such as VcXsrv or Xming)
- Install and launch VcXsrv (or another X server). When starting VcXsrv, select "Disable access control".
- Find your host IP that Docker can reach (often the
vEthernet (WSL)adapter address, e.g.192.168.x.x). - Run (replace
<host-ip>with your actual IP):
docker run --rm \
-e DISPLAY=<host-ip>:0 \
particle-sim python verlet.py -n 50 -s 1000 -vdocker run --rm particle-sim python runtests.py