Abstract Particle Physics Simulation with Python and py5

2026/8/21

Visualizing the invisible forces that govern the universe is a core pursuit in both science and generative art. In this experiment, I wanted to simulate the chaotic beauty of a high-energy particle accelerator. By recreating the mechanics of subatomic collisions and particle decay in 3D space, I generated a cinematic, continuous cascade of glowing matter spiraling through abstract magnetic fields.Using Python and py5, I built a lightweight but highly dynamic physics engine that manages thousands of particles simultaneously, employing real-time additive blending and procedural noise to bring the simulation to life.

The Visual and Aesthetic Approach

The aesthetic of the simulation mirrors the classical bubble chamber or cloud chamber photographs from mid-20th-century physics, but rendered in vibrant neon colors. The scene takes place in a dark void. When high-energy collisions occur at the center, particles explode outward.To create a volumetric and luminous effect, the rendering uses additive blending (py5.ADD). As particles travel, they leave solid trails. The trails fade out gradually based on the particle's remaining lifespan. The camera slowly orbits the scene, giving the viewer a true 3D perspective of the spiraling, explosive architecture of the particle tracks.

Technical Breakdown: Particle Decay and Lifespans

A unique feature of this simulation is the parent-child decay system. Real subatomic particles often decay into smaller constituent particles mid-flight. The Particle class tracks its "generation" to handle this.
# Sub-collisions/decays
if p.parent_gen < 2 and random.random() < 0.02:
    for _ in range(random.randint(2, 5)):
        sub_vel = p.vel * 0.5 + np.random.randn(3) * random.uniform(1.0, 5.0)
        new_particles.append(Particle(p.pos, sub_vel, p.size * 0.7, p.color, random.randint(20, 60), p.parent_gen + 1))
    p.life = 0 # Parent dies
During the update loop, there is a small probability (0.02) that a particle will spontaneously decay. When it does, it splits into multiple smaller "child" particles (up to generation 2) that inherit a portion of the parent's velocity, mixed with random kinetic scatter. The parent particle immediately dies (p.life = 0). This creates abrupt, branching paths characteristic of real particle collisions.

Magnetic Fields and Helical Trajectories

Charged particles moving through a magnetic field experience a Lorentz force perpendicular to their velocity, causing them to spiral. To simulate this efficiently, I utilized vector cross products.
def update(self):
    # Magnetic field spiraling effect
    # Cross product of velocity and a magnetic field pointing mostly in Z
    B = np.array([0.0, 0.0, 1.0])
    force = np.cross(self.vel, B) * 0.1
    self.vel += force
    
    # Add a bit of noise
    noise_vec = np.array([
        py5.os_noise(self.pos[0] * 0.005, self.pos[1] * 0.005, py5.frame_count * 0.01),
        py5.os_noise(self.pos[1] * 0.005, self.pos[2] * 0.005, py5.frame_count * 0.01),
        py5.os_noise(self.pos[2] * 0.005, self.pos[0] * 0.005, py5.frame_count * 0.01)
    ]) * 0.5 - 0.25
    self.vel += noise_vec
By defining a static magnetic field B pointing along the Z-axis, the np.cross(self.vel, B) calculation generates a force that continually pulls the particle into a helical orbit. To keep the paths from looking too rigid or mathematically perfect, I overlay a 3D OpenSimplex noise vector (noise_vec). The resulting trajectories are both structured by physics and organic due to the procedural turbulence.
ambient subatomic particle collisions 3d p1

Conclusion

Building a custom physics engine for particle decay and magnetic spiraling reveals how elegantly complex behaviors can emerge from simple mathematical rules. Python, numpy, and py5 provide a remarkably fluid environment for prototyping these generative simulations, turning abstract mathematics into glowing, cinematic artwork.