This is the Holme–Kim model (Holme & Kim, 2002) — a growth process that reproduces the one property plain random-attachment graphs get wrong about real social networks: your friends tend to know each other. It's the same growth mathematics as the 3D version of this simulator, paired here with a genuinely different, independently-computed 2D mechanic: a planar spring-repulsion force layout (not a flattened 3D scene) plus two live statistical plots that have no 3D equivalent.
Each new node adds m edges:
1st edge → a uniformly random existing node u
edge i>1 → with probability p: a random neighbour of the
previously-attached node (closes a triangle)
else: a uniformly random existing node
The triadic-closure step is exactly "friend of a friend": if you just connected to person A, there's a chance your next connection is one of A's existing contacts, not a stranger. That single rule is what pushes local clustering far above what pure random attachment produces.
Local clustering: Cᵢ = 2·Tᵢ / (kᵢ(kᵢ−1))
Tᵢ = triangles through node i, kᵢ = degree of node i
Network average: C̄ = (1/N) Σᵢ Cᵢ
Random-graph (Erdős–Rényi) expectation for the same size: C ≈ ⟨k⟩ / N
2D layout physics (independent of the 3D version's 3D-vector layout):
repulsion Fᵢⱼ = k_r / d² (Coulomb-like, planar)
spring Fᵢⱼ = k_s · (d − L₀) (Hooke's law along each edge)
+ soft boundary containment force keeping every node on-canvas
+ velocity damping each step until the layout reaches equilibrium
- p = 0 — pure random attachment, no preference for closing triangles; C̄ stays close to the random-graph baseline.
- p → 1 — nearly every extra edge closes a triangle; C̄ climbs sharply above the baseline while the network keeps growing at the same rate, matching what's measured in real friendship and collaboration graphs.
- m — more edges per arriving node means a denser, more connected graph overall (higher ⟨k⟩), independent of the clustering effect.
- Graph diameter — the longest shortest path between any two nodes, recomputed exactly by breadth-first search from every node each time the graph changes (cheap at this scale); triadic closure tends to keep it small even as clustering rises, the "small-world" signature of real social graphs.