Logo

Non-Euclidean Worms

The classic snake game on flat, spherical, hyperbolic, and dynamically curved surfaces. From my Differential Geometry Final Project.

Score: 0

Non-Euclidean Worms

Arrow keys to move

Arrow keys to steer.

Euclidean Geometry (Flat)

The Euclidean board lives inside a disk. The worm moves at constant speed in a flat plane. Distances follow the familiar metric:

\[ ds^2 = dx^2 + dy^2 \]

Gaussian curvature is zero everywhere. Parallel lines stay parallel, triangle angles sum to exactly \(\pi\), and the circumference of a circle of radius \(r\) is \(2\pi r\). The boundary is a hard wall.

Spherical Geometry (Positive Curvature)

The spherical board maps the game onto \(S^2\), rendered via orthographic projection. The worm travels along lines of latitude and longitude. The metric on the sphere is:

\[ ds^2 = d\theta^2 + \sin^2\!\theta \; d\phi^2 \]

At the equator, cells have full width. Near the poles, the factor \(\sin\theta \to 0\) and longitude lines converge. The poles are singularities — reaching one kills the worm. The Gaussian curvature is constant: \(K = 1/R^2\).

Hyperbolic Geometry (Negative Curvature)

The hyperbolic board uses the Poincaré disk model. The worm moves continuously forward; steer with left/right arrows. The metric is:

\[ ds^2 = \frac{4(dx^2 + dy^2)}{(1 - x^2 - y^2)^2} \]

The conformal factor \(\lambda = 2/(1 - r^2)\) diverges at the boundary, meaning the boundary is infinitely far away in hyperbolic distance. Curvature is constant: \(K = -1\).

Dynamic Curvature

The dynamic mode starts flat (\(K=0\)) and changes curvature when the worm eats colored apples. Blue apples decrease \(K\) (more hyperbolic), yellow apples increase \(K\) (more spherical), and red apples just grow the worm.

The movement metric interpolates continuously. For \(K < 0\) the worm slows near the boundary (hyperbolic drag); for \(K > 0\) it accelerates (spherical expansion). Concentric circles on the board show equal geodesic distances, which compress or expand as curvature shifts.

\[ r_{\text{euclidean}} = \begin{cases} \tanh(\rho/2) / \sqrt{|K|} & K < 0 \\ \rho & K = 0 \\ \tan(\rho/2) / \sqrt{K} & K > 0 \end{cases} \]

Gauss-Bonnet Theorem

All three constant-curvature geometries are unified by the Gauss-Bonnet theorem. For a closed surface \(M\):

\[ \int_M K \, dA = 2\pi \, \chi(M) \]

where \(\chi\) is the Euler characteristic. For the sphere \(\chi = 2\), for the torus \(\chi = 0\), and for hyperbolic surfaces of genus \(g \geq 2\), \(\chi = 2 - 2g\). The total curvature is a topological invariant.