A mesmerizing ASCII art animation of a rotating donut rendered in your terminal, written in C. This program creates a 3D donut (torus) that rotates in space, using ASCII characters to create the illusion of depth and movement.
The program uses mathematical principles to create a 3D rendering of a torus (donut shape) in ASCII art:
- Creates a rotating torus using parametric equations
- Projects 3D coordinates onto a 2D space
- Calculates lighting and shadows
- Renders the result using ASCII characters for different lighting levels
- Updates the display in real-time for animation
- Clone the repository:
git clone https://github.com/maty7253/donut.git
cd donut
- Compile the program:
gcc -o donut donut.c -lm
Run the compiled program:
./donut
To exit the program, press Ctrl+C
.
The program uses several mathematical concepts:
- Torus Generation: Uses parametric equations to generate points on a torus surface
- 3D Rotation: Implements rotation matrices for 3D animation
- Projection: Converts 3D coordinates to 2D screen space
- Illumination: Calculates surface normals for basic lighting effects
- ASCII Rendering: Maps brightness levels to ASCII characters
A
andB
: Rotation anglesi
andj
: Parameters for torus generationz[]
: Z-buffer for depth handlingb[]
: Character buffer for ASCII output
This project is open source and available under the MIT License.
This implementation is inspired by the classic donut.c code by Andy Sloane, demonstrating the beauty of mathematical visualization through ASCII art.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.