donut.asm when compiled and run in console(80x22) renders a 3D spinning donut using ASCII characters. Each frame calculates the 3D surface of a donut, applies lighting, and displays it as text characters based on brightness.
- Windows
- NASM assembler
- MinGW GCC compiler
-
Assemble the source code:
nasm.exe -f win32 donut.asm -o donut.obj
-
Link the object file to create the executable:
gcc.exe donut.obj -o donut.exe -lkernel32 -luser32
-
Run the executable:
donut.exe
- Generates 3D points on a donut surface using parametric equations
- Rotates the donut in 3D space
- Projects 3D coordinates to 2D screen positions
- Calculates lighting based on surface normals
- Maps brightness to ASCII characters (
.,-~:;=!*#$@) - Uses Z-buffering for proper depth handling
Torus parametric equations:
x = (R + rcos(θ)) * cos(φ) y = (R + rcos(θ)) * sin(φ) z = r * sin(θ)
- R: Distance from the center of the tube to the center of the torus
- r: Radius of the tube
- θ, φ: Angles that parametrize the surface
Based on Andy Sloane's donut.c - donut math explanation