Non-Euclidean Worms
The classic snake game on flat, spherical, hyperbolic, and dynamically curved surfaces. From my Differential Geometry Final Project.
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:
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:
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\).
- Triangles have angle sums exceeding \(\pi\); the excess equals \(\text{Area}/R^2\)
- The "top" and "bottom" are single points (poles), not edges
- Use WASD to rotate the camera, arrow keys to steer the worm
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:
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\).
- Exponentially more space near the edge — area of a hyperbolic disk of radius \(\rho\) is \(2\pi(\cosh\rho - 1) \sim \pi e^{\rho}\)
- Geodesics are arcs of circles orthogonal to the boundary
- Triangles have angle sums less than \(\pi\)
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.
Gauss-Bonnet Theorem
All three constant-curvature geometries are unified by the Gauss-Bonnet theorem. For a closed surface \(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.