RepositoryPythonCNChina
NE

neozhaoliang/pywonderland

A tour in the wonderland of math with python.

4.2kstars
348forks
5issues
1views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: uniform-spanning-tree

#1 Repository of the month

1
TINIX TRENDING·Topic: coupling-from-the-past

#1 Repository of the month

1
TINIX TRENDING·Topic: coxeter-groups

#1 Repository of the month

A Tour in the Wonderland of Math with Python

A collection of python scripts for drawing beautiful figures and animating interesting algorithms in mathematics.

About this repo

The purpose of this project is to show the beauty of math with python by rendering high quality images, videos and animations. It consists of several independent projects with each one illustrates a special object/algorithm in math. The topics are chosen largely due to my personal taste:

  1. They must produce appealing results.
  2. There must be some non-trivial math behind them.
  3. The code should be as simple as possible.

What's fun here

  • Todd-Coxeter algorithm and uniform polytopes

    Use Todd-Coxeter algorithm to compute the data of a polytope, and render it in POV-Ray.

    [Book] | [Doc]

  • Möbius transformations

    • When a Möbius transformation is an isometry of the hyperbolic disk, it must be of elliptic/parabolic/hyperbolic type, and it's elliptic/parabolic/hyperbolic if and only if it's a composition of reflections about two intersecting/parallel/hyper-parallel mirrors.

    • A Möbius transformation can be uniquely extended to an isometry of the hyperbolic upper-half space.

  • Coxeter automata and 2D Uniform tilings

    [Casselman's Paper] | [Doc]

  • GIF animations of maze and cellular automata

    Generate maze animations containing thousands of frames in a few seconds. No external libs used and no drawing api call!

    [Doc]

  • Domino shuffling algorithm

    This algorithm samples a perfectly random tiling of a aztec diamond.

    [Mathologer Video] | [Paper]

  • Propp and Wilson's coupling from the past algorithm

    [Book]

  • Catacaustics of plane curves

    Use sympy to compute catacaustics of parametric and implicit curves.

    Cardioid as a catacaustic of circleNephroid as a catacaustic of cardioid
  • Coxeter element and Coxeter plane

    We explain how to project the E8 root system to its Coxeter plane.

    [Casselman's Paper]

    E85-Cube
  • Assassin vs Bodyguards

    Consider a room of regular polygon shape in the xy-plane, and let A (an "assassin") and T (a "target") be two arbitrary-but-fixed points within the room. Suppose that the room behaves like a billiard table, so that any ray (a.k.a "shot") from the assassin will bounce off the walls of the room, with the angle of incidence equaling the angle of reflection.

    Puzzle: Is it possible to block any possible shot from A to T by placing a finite number of points in the room?

    [PBS Video] | [math3ma blog]

  • Periodic solutions of the three-body problem

  • The beauty of roots

    [John Baez's blog post]

  • Circle packings from Bianchi groups

    [Alex Kontorovich's site]

  • Penrose cooling process

    [Thomas Fernique's gallery]

How to use

All projects here are implemented in a ready-to-use manner for new comers. You can simply run the examples without tweaking any parameters once you have the dependencies installed correctly.

Dependencies

The recommended way to install all dependencies is simply running the bash script install_dependencies.sh.

sudo bash install_dependencies.sh

Or you can install the python libs by pip:

pip install -r requirements.txt

Open source softwares required:

  • python3-tk (for file dialog)
  • ImageMagick (for making gif animations)
  • FFmpeg (for saving animations to video files)
  • POV-Ray (for generating high quality raytracing results)
  • graphviz (for drawing automata of Coxeter groups)
  • Inkscape (optional, for convering large svg files to png)

They can all be installed via command-line:

sudo apt-get install python3-tk imagemagick ffmpeg povray graphviz inkscape

Note pygraphviz also requires libgraphviz-dev:

sudo apt-get install libgraphviz-dev

In the scripts these softwares are called in command line as povray, ffmpeg, convert (from ImageMagick), etc. For Windows users you should add the directories contain these .exe files to the system Path environment variables to let the system know what executables these commands refer to. For example on Windows the default location of POV-Ray's exe file is C:\Program Files\POV-Ray\v3.7\bin\pvengine64.exe, so you should add C:\Program Files\POV-Ray\v3.7\bin to system Path and rename pvengine64.exe to povray.exe, then you can run the scripts without any changes and everything should work fine.

Thanks

I have learned a lot from the following people:

License

see the LICENSE file.

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
donnemartin/system-design-primer

Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.

379.9k
Sep 15, 2026
RepositoryPython
practical-tutorials/project-based-learning

Curated list of project-based tutorials

290.9k
Nov 30, 2026
RepositoryPython
microsoft/markitdown

Python tool for converting files and office documents to Markdown.

199.5k
Dec 2, 2026
RepositoryPython
Significant-Gravitas/AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

188.2k
Nov 29, 2026
RepositoryPython
Comfy-Org/ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

149.6k
Dec 2, 2026
RepositoryTypeScript
morluto/rea

Reverse engineer anything with agents, from app behavior down to native binaries.

487.0k
Dec 2, 2026
RepositoryTypeScript
freeCodeCamp/freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.

459.9k
Dec 2, 2026
RepositoryTypeScript
nilbuild/developer-roadmap

Interactive roadmaps, guides and other educational content to help developers grow in their careers.

373.1k
Dec 1, 2026
RepositoryJavaScript
react/react

The library for web and native user interfaces.

253.0k
Nov 30, 2026