No description
  • Rust 71.2%
  • Python 28.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Benno Richters dd1d3ab653 Add rust-checks Stop hook
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 11:35:27 +01:00
.claude Add rust-checks Stop hook 2026-10-25 11:35:27 +01:00
assets new screenshots 2025-12-19 09:39:23 +01:00
data-scripts Add Riemann zeta critical line data generator 2026-10-11 11:46:55 +02:00
src Reuse render buffers between frames and simplify line drawing 2026-10-11 11:39:32 +02:00
.gitignore removed data file 2025-12-17 12:56:04 +01:00
Cargo.lock Refactor walks, CLI, key bindings and vector math 2026-10-11 11:25:20 +02:00
Cargo.toml Refactor walks, CLI, key bindings and vector math 2026-10-11 11:25:20 +02:00
CLAUDE.md Add rust-checks Stop hook 2026-10-25 11:35:27 +01:00
LICENSE Create LICENSE 2025-12-11 13:45:25 +01:00
README.md Add Riemann zeta critical line data generator 2026-10-11 11:46:55 +02:00

3D Prime Walk

DISCLAIMER: This README is generated by Claude.

A mesmerizing visualization that creates a walk through three-dimensional space, where the path changes direction at every prime number. The program generates a colorful spiral pattern that reveals the mathematical beauty hidden within the distribution of prime numbers.

How It Works

The program starts at the origin and begins walking in a single direction through 3D space. With each step, it counts upward from zero. Whenever the step count reaches a prime number (2, 3, 5, 7, 11, 13, ...), the walker changes direction according to a fixed sequence:

  1. Right (positive X)
  2. Up (positive Y)
  3. Forward (positive Z)
  4. Left (negative X)
  5. Down (negative Y)
  6. Backward (negative Z)

After the sixth direction change, the sequence repeats. This creates an intricate three-dimensional path that weaves through space, its turns dictated by the distribution of prime numbers. The resulting structure is both mathematically significant and visually striking.

Each step along the path is colored according to a gradient that transitions from red at the beginning to blue at the end, making it easy to see the progression of the walk and trace how the pattern unfolds over time.

Visualization

3D Prime Walk Screenshot

3D Prime Walk Animation

The program projects the 3D walk onto a 2D screen using a sophisticated camera system with proper depth sorting, ensuring that closer points appear in front of more distant ones. The resulting image can be freely manipulated, allowing you to orbit around the structure and examine it from any angle. 75

Interactive Controls

The visualization is fully interactive, giving you complete control over the camera:

Rotation

  • H / L - Rotate horizontally (decrease/increase azimuth)
  • J / K - Rotate vertically (decrease/increase polar angle)
  • R / Shift+R - Roll camera (decrease/increase rotation angle)

Camera Distance

  • Z - Move camera closer to the structure
  • Shift+Z - Move camera away from the structure

Focal Length

  • F - Decrease focal length (narrower field of view)
  • Shift+F - Increase focal length (wider field of view)

Orbit Center

Movement follows the screen, not the world axes:

  • A / Shift+A - Move center point along the screen's horizontal axis
  • S / Shift+S - Move center point along the screen's vertical axis
  • W / Shift+W - Move center point toward/away from the camera

Reset

  • D - Reset all camera values to defaults

The left panel displays real-time information about the camera position, including the current azimuth, polar angle, rotation angle, center point coordinates, camera radius, and focal length.

Building and Running

This project is written in Rust and requires a Rust toolchain to build.

Prerequisites

  • Rust (edition 2024 or later)

Running the Program

# Run with defaults (25,000 steps, red to blue gradient, prime_walk mode)
cargo run --release

# Run with custom number of steps
cargo run --release -- --steps 10000

# Run with custom gradient colors (format: R,G,B)
cargo run --release -- --start-color 0,255,0 --end-color 255,0,255

# Run with custom walk type
cargo run --release -- --walk-type data_walk

# Combine multiple options (order doesn't matter!)
cargo run --release -- --start-color 255,255,0 --walk-type data_walk

# Read data from another file
cargo run --release -- -w data_walk --data path/to/points.csv

# Using short flags
cargo run --release -- -n 5000 -s 255,0,0 -e 0,255,0 -w prime_walk

# Get help
cargo run --release -- --help

The --release flag is recommended for optimal performance when rendering the visualization.

Command-Line Arguments

All arguments are optional and can be specified in any order:

  • --steps, -n: Number of steps (default: 25,000)
  • --start-color, -s: Start color in R,G,B format (default: 255,0,0 - red)
  • --end-color, -e: End color in R,G,B format (default: 0,0,255 - blue)
  • --walk-type, -w: Type of walk (default: prime_walk)
    • prime_walk - Visualize the distribution of prime numbers in 3D space
    • data_walk - Visualize custom coordinate data (requires data file from data-scripts/)
  • --data, -d: Data file read by data_walk, one x,y,z per line (default: data, relative to the current directory)

Colors must be specified as three comma-separated values between 0-255 (e.g., 255,128,0 for orange).

Using Data Walk Mode

The data_walk option visualizes custom 3D coordinate data instead of prime numbers. To use this mode, you must first generate a data file using one of the Python scripts in the data-scripts/ folder.

Prerequisites for Data Scripts

  • Python 3.x

Available Data Generators

The data-scripts/ folder contains five coordinate generators:

1. Lorenz Attractor (generate_lorenz.py)

Generates the famous chaotic Lorenz attractor pattern:

cd data-scripts
python3 generate_lorenz.py
cd ..
cargo run --release -- --walk-type data_walk

3D Prime Walk Screenshot

2. 3D Lissajous Curves (generate_lissajous.py)

Creates beautiful flowing patterns with configurable frequency ratios and phases:

cd data-scripts

# Default pattern (3:4:5 frequencies)
python3 generate_lissajous.py

# Custom frequency ratio (flowing ribbon pattern)
python3 generate_lissajous.py --a 1 --b 2 --c 3

# Complex woven structure
python3 generate_lissajous.py --a 3 --b 5 --c 7

# Adjust amplitude (size)
python3 generate_lissajous.py --amp 150

# View all options
python3 generate_lissajous.py --help

cd ..
cargo run --release -- --walk-type data_walk

3. Torus Knots (generate_torus_knot.py)

Generates mathematical knots that wrap around a torus:

cd data-scripts

# Trefoil knot (default)
python3 generate_torus_knot.py

# Cinquefoil knot (5-petaled pattern)
python3 generate_torus_knot.py --p 5 --q 2

# Complex interweaving
python3 generate_torus_knot.py --p 5 --q 3

# Adjust size
python3 generate_torus_knot.py --R 150 --r 80

# View all options
python3 generate_torus_knot.py --help

cd ..
cargo run --release -- --walk-type data_walk

4. Spiral Sphere (generate_spiral_sphere.py)

Generates a spiral that winds 30 times around a sphere from pole to pole:

cd data-scripts
python3 generate_spiral_sphere.py
cd ..
cargo run --release -- --walk-type data_walk

5. Riemann Zeta Function (generate_zeta.py)

Follows ζ(1/2 + it) along the critical line, with the real and imaginary parts as two axes and t as the third. The curve winds around the central axis faster and faster and passes exactly through it at every nontrivial zero of ζ, the zeros that encode the distribution of the primes:

cd data-scripts

# The first 29 zeros (t from 0 to 100, default)
python3 generate_zeta.py

# Only the first few zeros
python3 generate_zeta.py --t-max 40

# Higher up the critical line, a tighter coil
python3 generate_zeta.py --t-min 1000 --t-max 1050

# Flatten the t axis to see the classic 2D spiral
python3 generate_zeta.py --height 1

cd ..
cargo run --release -- --walk-type data_walk

All scripts generate a file named data in the project root directory (no matter which directory you run them from), which is read by the program when using --walk-type data_walk. You can customize colors and other parameters:

# Run with custom colors on generated data
cargo run --release -- --walk-type data_walk --start-color 0,255,0 --end-color 255,0,255

# Generate data with custom point count
cd data-scripts
python3 generate_lissajous.py --steps 50000
cd ..
cargo run --release -- --walk-type data_walk

Technical Details

  • Language: Rust
  • GUI Framework: eframe/egui
  • Default Steps: 25,000 (configurable via command-line argument)
  • Rendering Resolution: 800x800 pixels
  • Default Color Gradient: Red (255, 0, 0) to Blue (0, 0, 255) (configurable via command-line arguments)

The program uses the Sieve of Eratosthenes algorithm to efficiently generate prime numbers and implements a custom 3D projection system with plane intersection calculations for accurate rendering.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Benno Richters