Home▸Drawing with Maths▸2D Chaos Game

🎲 2D Chaos Game — Polygon Vertex Fractal

A genuine 2D chaos-game fractal generator: jump a real fraction r toward a random vertex of an N=3..8 polygon and watch the Sierpinski triangle and other attractors emerge point by point. Toggle the forbidden-previous-vertex rule.

Drawing with Maths2DEasy60 FPS📱 Mobile-adapted⇄ 3D version
2d-chaos-game ↗ Open standalone

The classic vertex chaos game: repeatedly jump a real fraction r of the distance toward a randomly chosen vertex of a regular N-gon, plotted point by point directly on a flat 2D canvas. At N=3, r=0.5 the exact Sierpinski triangle emerges; other N and r values reveal different attractors, and the optional forbidden-previous-vertex rule reshapes the pattern further.

🔬 What It Demonstrates

Each iteration follows pₙ₊₁ = pₙ + r·(vertex − pₙ): a contraction toward a randomly chosen point. Because the map always contracts, the sequence of points converges onto a fixed fractal attractor regardless of the starting point — a direct, hands-on illustration of the Banach fixed-point theorem behind every iterated function system.

🎮 How to Use

Adjust Vertices N (3–8) and Ratio r to explore different attractors. Use Speed to control how many iterations run per frame, toggle Forbid previous vertex to exclude the last-used vertex from the next pick, and Pause/Restart to freeze or reseed the random walk.

💡 Did You Know?

With N=5 (a pentagon) and r=0.5, plain i.i.d. vertex sampling fills in a dense blob rather than a clean fractal — but forbidding the previously used vertex thins the orbit into a delicate five-fold fractal pattern, a striking demonstration of how a single extra rule reshapes a chaos-game attractor.

About the 2D Chaos Game — Polygon Vertex Fractal Simulation

This simulation runs the original vertex chaos game directly on a 2D canvas. A regular N-gon (N from 3 to 8) is drawn, a point starts at the polygon's centroid, and on every iteration a vertex is chosen at random and the point jumps a fraction r of the remaining distance toward it. There is no pre-computed image — every frame genuinely advances the random walk, and the recognisable fractal shape emerges from the accumulating cloud of points.

At the classic settings N=3 and r=0.5, the attractor is exactly the Sierpinski triangle, with Hausdorff dimension log(3)/log(2) ≈ 1.585. Changing N or r produces entirely different attractors — some solid, some sparse — and toggling the forbidden-previous-vertex rule (which excludes the vertex used on the last jump from the next random pick) reshapes the pattern again, since it changes the underlying random process the chaos game is sampling from.

Frequently Asked Questions

How is this different from the 2D Barnsley Fern simulation?

The Barnsley fern uses four fixed affine transformations (rotation, shear and scale coefficients) chosen with weighted probabilities to produce a naturalistic fern shape. This simulation instead uses the original, simpler chaos game: plain point-to-vertex jumps toward the corners of a regular polygon, with adjustable vertex count N and jump ratio r, plus an optional rule that forbids repeating the previous vertex. The two use the same underlying "jump a fraction toward a random target" mechanic but explore very different families of attractors.

Why does N=3, r=0.5 produce the Sierpinski triangle?

Jumping halfway toward one of three triangle vertices is a contraction mapping that scales the plane by 1/2 toward that vertex. The unique attractor of these three contractions is exactly the Sierpinski triangle. Changing r changes the effective contraction ratio (1 − r), so other values of r no longer produce the classic Sierpinski pattern even with N=3.

What does the "forbidden previous vertex" rule change?

Without the rule, each vertex is chosen independently and identically at random (i.i.d.), which is the classical chaos game. With the rule enabled, the vertex used on the previous jump is excluded from the next pick. This is no longer i.i.d. sampling — it correlates consecutive choices — and for several N/r combinations it reveals a distinctly different, often more delicate, fractal pattern than free sampling produces.

What is the exact chaos-game update rule used here?

Given the current point p and a randomly chosen vertex v of the N-gon, the next point is p' = p + r·(v − p), where r is the adjustable jump ratio (0.1 to 0.9). This is applied one iteration at a time and each resulting point is plotted immediately — a genuine random walk, not a static rendering.

What is the Chaos Game algorithm?

The Chaos Game is a probabilistic algorithm introduced by Michael Barnsley in his 1988 book "Fractals Everywhere." Rather than computing the attractor analytically, you pick a random starting point and repeatedly apply a randomly chosen contraction map. For almost every starting point, the orbit eventually traces the exact attractor — which is exactly what this simulation renders live, point by point, on the 2D canvas.

Do all N and r combinations produce clean fractals?

No — some combinations (for example large r values with free vertex sampling) cause the orbit to spend most of its time very close to the polygon's vertices and edges, filling in solidly rather than revealing fine fractal structure. Smaller r values and the forbidden-vertex rule tend to produce the most visually striking, sparse fractal traceries.

Can I break the pattern by choosing extreme settings?

You can't produce invalid output — the update rule always keeps the point inside the polygon's convex hull — but very high or very low ratio values can make the attractor collapse toward the vertices themselves (r near 1) or toward the centroid (r near 0), producing much less visually interesting fractal detail than the mid-range values.

⚙ Under the hood

A genuine 2D chaos-game fractal generator: jump a real fraction r toward a randomly chosen vertex of an adjustable N=3..8 polygon and watch the Sierpinski triangle and other attractors emerge point by point, with an optional forbidden-previous-vertex rule.

Chaos GameSierpinski TriangleIterated Function SystemFractalPolygon Vertices

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)