This simulation lays out a randomly generated network using the Fruchterman-Reingold spring algorithm, where every node repels every other while connected nodes attract along their edges. You can switch between three classic graph models — Erdős-Rényi random, Barabási-Albert scale-free, and Watts-Strogatz small-world — and watch each settle into a characteristic shape. Nodes are coloured and sized by their degree, and a live histogram reveals how connections are distributed across the network.
An undirected graph drawn by a force-directed layout: a repulsive force k²/d acts between all node pairs, while edges pull endpoints together with force d²/k, plus a weak gravity term toward the centre. Three generators build the topology — uniform random wiring, preferential attachment that produces power-law hubs, and a ring lattice with rewiring that yields short path lengths with high clustering.
Pick a graph type with the Random, Scale-Free and Small-World buttons. The Nodes slider sets size from 20 to 150, and the Gravity slider (0–20) tightens or loosens the clustering toward the centre. Use ×1/×2/×4 to run more layout steps per frame, New Graph to regenerate, and Pause to freeze. Drag any node with the mouse or touch to perturb the layout.
In a Barabási-Albert scale-free network the degree distribution follows a power law, P(k) ∝ k⁻³, so a handful of richly connected hubs coexist with many sparsely linked nodes — the pattern seen in the long right-hand tail of the live histogram.
It is a method for drawing a network so that the picture reveals its structure. Each node is treated like a charged particle that pushes others away, while edges act like springs that pull connected nodes together. The system is simulated until the forces balance, leaving well-connected clusters close together and loosely linked nodes spread apart.
It computes a repulsive force of roughly k²/distance between every pair of nodes and an attractive force of distance²/k along each edge, where k is an ideal spacing derived from the canvas area and node count. Forces are summed, velocities are damped each step, and a small gravity pull keeps the graph centred, so the layout gradually relaxes into a stable arrangement.
The random (Erdős-Rényi) model connects each pair of nodes with a fixed small probability, giving a bell-shaped degree distribution. The scale-free (Barabási-Albert) model grows by preferential attachment, so new nodes favour already-popular ones and large hubs emerge. The small-world (Watts-Strogatz) model starts from a regular ring and rewires a fraction of edges, producing short paths with high local clustering.
Both encode each node's degree, the number of edges attached to it. Low-degree nodes appear blue and small, while high-degree hubs shift through green toward orange and grow larger. The side panel also reports node and edge counts, average and maximum degree, and density, alongside a histogram of the full degree distribution.
It is a faithful implementation of the Fruchterman-Reingold heuristic rather than a model of real physics, so the forces are chosen for clear, readable diagrams rather than to reproduce nature. Repulsion is computed for all pairs, which is exact but scales as the square of the node count, so the simulation caps the network at 150 nodes to stay smooth in the browser.