The Schelling Segregation sketch starts from a mixed grid, lets you adjust tolerance, empty space, and group count, then shows how quickly a neighborhood can sort itself into color blocks once enough agents decide their local mix feels wrong.
Thomas Schelling's segregation model keeps returning because it stages an ugly civic fact in stripped-down form. The Wikipedia summary still captures the core point cleanly: agents need only a mild in-group preference for large-scale separation to emerge, even when nobody is demanding total exclusion. That is also the premise behind Nicky Case and Vi Hart's Parable of the Polygons, which turned the model into a widely shared explorable explanation. This sketch belongs to that lineage. It puts the mechanism on screen and lets the threshold do the talking.
The useful thing about this version is its refusal to hide the rule. An agent checks the eight adjacent cells, ignores empties, and asks whether enough neighbors match. If the answer falls below the current tolerance, the agent moves. That is the whole engine, and it is enough to produce those hard rectangular neighborhoods that look intentional long before any single step feels dramatic. The model leaves out landlords, redlining, zoning, policing, and every other institutional force that structures actual segregation. Schelling's point was narrower. Local preference alone can organize a city faster than common sense expects.
You can see that logic directly in gallery/schelling.html:
function isHappy(idx) {
if (grid[idx] === EMPTY) return true;
const me = grid[idx];
const nbrs = neighbors(idx);
let same = 0, total = 0;
for (const n of nbrs) {
if (grid[n] !== EMPTY) {
total++;
if (grid[n] === me) same++;
}
}
if (total === 0) return true;
return (same / total) >= getTolerance();
}
I like how plain this implementation stays. Happiness is a ratio, not a speech about identity. Movement is random relocation into available empties, which keeps the sketch close to the model's conceptual grain. Run it with a low tolerance and the field holds together longer. Push the slider upward and pockets start crystallizing into districts. The artifact makes one of Schelling's most unsettling insights legible at browser speed. Small private thresholds can accumulate into public structure, and once the grid begins to harden, the pattern looks much more deliberate than the motives that produced it.
Schelling Segregation
A live agent-based segregation model with controls for similarity tolerance, vacancy rate, and number of groups, plus stepwise and continuous playback.
View artifact โ Open gallery sketch โOther systems posts include Where the Boundary Learns to Breathe, The Heuristic That Lets Search Hurry, Life Starts at the Edge of Control, and Ising Spins.