Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
/ Donut.c Public archive

🍩 A Comprehensive Guide on the Math used in Donut.c

Notifications You must be signed in to change notification settings

sleepymalc/Donut.c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Donut.c

A Comprehensive Guide on the Mechanism of Donut.c

Introduction

Back in 2006, there was an interesting c project on the internet called Donut.c1, which not only looks like a donut but can also print the ASCII characters in the terminal of a rotating donut.

             k;double sin()
         ,cos();main(){float A=
       0,B=0,i,j,z[1760];char b[
     1760];printf("\x1b[2J");for(;;
  ){memset(b,32,1760);memset(z,0,7040)
  ;for(j=0;6.28>j;j+=0.07)for(i=0;6.28
 >i;i+=0.02){float c=sin(i),d=cos(j),e=
 sin(A),f=sin(j),g=cos(A),h=d+2,D=1/(c*
 h*e+f*g+5),l=cos      (i),m=cos(B),n=s\
in(B),t=c*h*g-f*        e;int x=40+30*D*
(l*h*m-t*n),y=            12+15*D*(l*h*n
+t*m),o=x+80*y,          N=8*((f*e-c*d*g
 )*m-c*d*e-f*g-l        *d*n);if(22>y&&
 y>0&&x>0&&80>x&&D>z[o]){z[o]=D;;;b[o]=
 ".,-~:;=!*#$@"[N>0?N:0];}}/*#****!!-*/
  printf("\x1b[H");for(k=0;1761>k;k++)
   putchar(k%80?b[k]:10);A+=0.04;B+=
     0.02;}}/*****####*******!!=;:~
       ~::==!!!**********!!!==::-
         .,~~;;;========;;;:~-.
             ..,--------,*/

And recently it is widely spread and discussed through the internet, and after we look into the source code, we find out that the whole algorithm is based on what we have learned in Vv214. From here, we want to do some deep research and expand this project based on the current one.

Report

The Donut.c.pdf provides a short but comprehensive slide to walk you through all the math behind Donut.c.

Due to the .gif in the presentation slides, please only use Adobe Acrobat to open the .pdf, in this way it can work properly as it should.

About Honor Code

If there is the same project in the future in VV214, it is the responsibility of JI students not to copy or modify these codes, or $\TeX$ files because it is against the Honor Code. The owner of this repository doesn't take any commission for others' faults. According to the SJTU student handbook (2019 version),

It is a violation of the Honor Code for students to submit, as their own, work that is not the result of their own labor and thoughts. This applies, in particular, to ideas, expressions or work obtained from other students as well as from books, the internet, and other sources. The failure to properly credit ideas, expressions or work from others is considered plagiarism.

Contribution

Chen Xiaoyu, Wu Jinyi, Pingbang Hu


The works are partially contributed by some other students, TAs, and professors in JI, which would be listed if known.

If you find any problems in the repository, welcome to make an issue or pull request.

Source

  1. Donut math: how donut.c works
  2. 3D computer graphics
  3. Z-Buffer Algorithm

Footnotes

  1. Note that we re-factorize the source code to make it human-readable. The original code is literally like a donut.

Releases

No releases published