Visualizations
279 / 500

279 · Math

Gaussian Primes

A frog hops across the Gaussian primes, looking for a way to infinity.

Gaussian integers a + bi are the lattice points of the plane, and the primes among them (a^2 + b^2 prime, or a prime of the form 4k + 3 on an axis) form a tapestry with the eightfold symmetry of the square; Eisenstein primes do the same on the triangular lattice with twelvefold symmetry. A frog starts at the origin and may only land on primes, jumping at most k. Whether some finite k lets it walk to infinity is the open Gaussian moat problem: computers have found moats for every jump up to the square root of 26 and beyond, but there is no proof. A breadth-first flood fill over a map of radius 1,100 finds every prime the frog can reach, a few hop layers per frame, and the union of disks of radius k / 2 around them is drawn as the frog's island, since two disks touch exactly when the frog can jump between them. When the flood stops, a second pass finds the narrowest gap across the moat, the frog hops there along a shortest path, and the jump widens to exactly that gap so it can leap across.

Try it. Drag the jump slider (or use the arrow keys and plus or minus) to change the maximum jump, and toggle Gaussian and Eisenstein primes with the button or E. Click any prime to drop the frog there and flood from it, and press Space to leap the moat once the frog is stuck. Drag to pan, scroll or pinch to zoom, and hover a prime to see its norm and how many hops it took.

  • Gaussian and Eisenstein primality
  • Breadth-first flood fill
  • Mosaic tile classification

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build an interactive picture of the Gaussian moat problem with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Use a deep teal background.
- Sieve the ordinary primes up to about 40,000 into a Uint8Array.
- A Gaussian integer a + bi is prime when a and b are both nonzero and a^2 + b^2 is prime, or when one is zero and the other's absolute value is a prime of the form 4k + 3. Draw every Gaussian prime with |a| and |b| up to 150 as a small square tile, colored by a few classes of its norm. It should look like a symmetric rug.
- A frog starts at the origin and may only land on primes, jumping at most k (start with sqrt 2). Run a breadth-first search over primes within k of each other and color every prime the frog can reach gold.

Once that works, make it beautiful:
- Run the search one layer per frame so the reachable region spreads like a flood, colored by hop count.
- Add a slider for k that only stops at real lattice distances (sqrt 2, 2, sqrt 5, sqrt 8, sqrt 10 and so on) and reruns the flood. Show how many primes were reached and how far out the frog got.
- Draw a small frog with ellipses and animate it hopping along a shortest path to the farthest prime it can reach.
- Give the background a mosaic look: small tiles with slightly varied colors and thin grout lines.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as Eisenstein primes on a triangular lattice, finding the narrowest gap across the moat, or drawing the frog's island as the union of disks of radius k / 2 around each reached prime.
PreviousOrb WeaverA garden spider builds a real orb web, step by step, then guards its dewy net. NextMax Flow WaterworksWater fills a hand-drawn pipe network until the minimum cut lights up in red.

Related visualizations

  • Prime SpiralsMath A million integers on Ulam and Sacks spirals, where prime-rich polynomials glow as rays.
  • Music of the PrimesMath Riemann's explicit formula rebuilds the prime staircase from 500 zeta zeros.
  • SLE CurvesMath Random fractal curves grown tip first from Loewner's equation, kappa by kappa.
  • Apollonian GasketFractals An endless packing of kissing circles, each engraved with its exact integer curvature.
  • Critical PercolationSimulation Open hexagons merge into a giant cluster the instant p crosses one half.
  • Lights Out AlgebraMath The toggle-tile puzzle solved instantly at any size by linear algebra over GF(2).
  • Gaussian Process InkMachine learning Exact GP posteriors painted as watercolor bands with inked function samples.
  • Bad Random NumbersMath RANDU looks random until you turn it, then 24,000 points snap into 15 planes.
  • Hyperbolic TilingMath An endless koi garden of {p,q} ponds tiling the Poincare disk, with fish circling.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs