This simulation implements a population of autonomous particles that behave as local agents rather than as elements of a centrally controlled system. Each particle follows the same simple set of rules, yet the collective behavior that emerges is non-trivial and often surprising. The goal is not to impose a global ordering mechanism, but to explore whether structured patterns—specifically sorting along a grayscale spectrum—can arise purely from local interactions.
The simulation is entirely decentralized. There is no global coordinator, no shared state, and no explicit instruction telling particles where to go. Every particle reacts only to nearby particles and to its own internal tendencies.
Each particle has:
A position and velocity in continuous 2D space.
A fixed grayscale value in the range [0,1][0,1][0,1], which remains constant throughout the simulation.
A small amount of inertia, meaning it cannot instantly change direction or speed.
A weak tendency to perform a random walk, introducing exploration and preventing the system from freezing in local minima.
Particles are rendered as points, with their color directly corresponding to their grayscale value.
Each simulation step applies several forces to every particle:
1. Long-range attraction based on similarity
Particles attract each other based on color similarity. The closer two particles are in grayscale value, the stronger their mutual attraction.
This attraction:
Decays exponentially with distance, allowing particles to “sense” similar particles even at relatively long ranges.
Is strongest between particles of nearly identical grayscale.
Approaches zero for particles with very different grayscale values.
This creates a soft, non-binary notion of affinity rather than hard clustering.
2. Short-range repulsion with a hard minimum distance
To prevent particles from collapsing into the same point, a repulsive force is applied whenever two particles come closer than a specified minimum distance.
Importantly:
This minimum distance is defined in screen pixels, not abstract world units.
The simulation dynamically converts pixel distance to world-space distance based on the camera and viewport.
As a result, particles are guaranteed to never overlap visually, regardless of zoom or screen size.
This ensures physical plausibility and avoids degenerate states where identical particles occupy the same location.
3. Weak random walk
Each particle receives a small, randomized force every frame.
This serves several purposes:
Prevents particles from becoming permanently stuck in symmetric or metastable configurations.
Allows clusters to slowly reorganize over time.
Introduces exploratory behavior without overpowering attraction or repulsion forces.
Crucially, the random walk is intentionally weak, so once compatible particles have formed stable groups, they are not torn apart.
The simulation uses a simple physical integration model:
Forces accumulate as acceleration.
Acceleration updates velocity.
Velocity updates position.
A maximum speed cap prevents numerical instability.
A friction parameter controls how quickly motion is damped.
This creates smooth, inertial motion rather than jittery or instantaneous responses.
Although no particle has any notion of a global gradient or target arrangement, the system often evolves toward spatial ordering:
Particles with similar grayscale values tend to cluster together.
Over time, these clusters may align into broader regions of similar tone.
The resulting structures are not enforced, stable, or guaranteed—they depend sensitively on parameter settings and initial conditions.
The simulation therefore functions as an open-ended experiment rather than a deterministic sorting algorithm.
All key parameters—attraction strength, decay rate, repulsion strength, minimum distance, random walk intensity, friction, and maximum speed—are exposed via a live control panel.
This allows users to:
Explore different regimes of behavior.
Observe phase transitions between dispersion, clustering, and ordering.
Develop intuition about how local rules give rise to global structure.
This system is inspired by ideas from:
Self-organizing systems
Agent-based modeling
Collective intelligence
Non-equilibrium dynamics
Rather than solving a predefined optimization problem, the simulation investigates how meaningful structure can emerge from minimal assumptions—and where such emergence fails.
In that sense, the simulation is less about particles and more about understanding the boundary between randomness, local rules, and global order.