Motivation
Somehow I stumbled over this C code generating a rotating torus inside a terminal. Might have been Lex Fridman’s video on it.
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;}}/*****####*******!!=;:~
~::==!!!**********!!!==::-
.,~~;;;========;;;:~-.
..,--------,*/
I really like terminal applications and manifolds so I thought it might be cool to see other surfaces in this manner. I’m quiet fond of the Möbius strip as a simple non-orientable surface.

Execution
For me the first step was understanding the original code, which was made infinitely easier by the authors own explanation. Then some refactoring was done to make the code more readable and allowed for plugging in other surfaces relatively easy. Of course this made the code not look like a shape anymore which seems to be a big appeal for most people. Also the code became much less efficient. These where trade-offs I was fine with though.
Möbius strip
The used parametrization of the Möbius strip is given as follows:
\begin{align} m:(-1,1)\times[-\pi,\pi] \longrightarrow &\ \mathbb{R}^3 \ \quad (x,y) \longmapsto &\ R_z(y) \Big(r_2\ e_1 + x R_y\left(\tfrac{y}{2}\right) e_1\Big) \ & = \left[\begin{smallmatrix} \cos y \left(2\ +\ x\cos\frac{y}{2}\right)\ \sin y \left(2\ +\ x\cos\frac{y}{2}\right) \ -x \sin\frac{y}{2}\end{smallmatrix}\right], \end{align}
where $e_1$ is the first base vector of $\mathbb{R}^3$. Furthermore e $R_z$ is the rotation matrix around the z-axis and $R_y$ is the rotation matrix around the y-axis. The constant $r_2$ corresponds to the diameter of the strip and is chosen to be 3, which means that the ring running along the center of the strip will be a circle of radius 3.
The luminance is also calculated using the surface normal as is the case in the original donut rendering. The surface normal of our parametrization is only dependent on the angle $y$ since given a fixed $y$ the image of $m$ is a short line an thus any orthogonal vector is invariant with respect to $x$. From this follows that the normal can be calculated as the third base vector $e_3$ of $\mathbb{R}^3$ rotated around the y-axis by $\frac{y}{2}$. This gives the following surface normal:
$$ n(y) = \left[\begin{smallmatrix} \sin\frac{y}{2}\ 0 \ \cos \frac{y}{2} \end{smallmatrix}\right] $$
The rotations used to rotate the Möbius strip are the same as in the original Donut code.
This is the result:

Other surfaces
Other surfaces that are impemented are the original torus
$$$$@@@@@
#$$#####$$$@@@
###*!!!!**##$$@@$
###**!=!!=!=!*#$$$$$
*#*!!==;:::;;!!*#$$$$#
!#*!!=::~,,-~~;=!*#$$$$*
***!=:~-..,,..~:=!*#$$$#
*#*!=;~-.,:;;~-.~:=*#$$$#*
***!=;-.-: -,~=!*#$$$#
!#**!=~,,; ,-:!*##$##;
*#**!;~.: ,:=*#####=
;*##*!;-, .:=*####*!
=###*!;- -:=*####*!
!####*;, :!*####*=
!####*=, ,;!*###**=
!#$$$#!- :=**###*!;
=#$$$$*: ;!*##***!;
=*$$$$#! ;!**#***!=:
;*#$$@$#; ;!**#***!=;.
:!#$$@@$#: =!**##***!=:
,;*#$@@@$#* !***##****!=:~
;!*$$@@@@$$#######***!!=;:
-;!#$$$@$$$$$####***!!=;:.
:!!*##$$$$$$###**!!!=;:,
.;=!**#######**!*!!=;:-
,:;!!!*******!!!=;;~,
.~;=!!!!=!!!=;;;:~.
,-~;;===;;;;::~,.
.,-~~~~~--,..
~,.....,~
and a simple cube that does not really appear cubical because a character is taller than wide
$$~
$$$$$$$
$$$$$$$$$$
$$$$$$$$$$$$$$~
$$$$$$$$$$$$$$$~~
$$$$$$$$$$$$$$$$~~~~~
$$$$$$$$$$$$$$~~~~~~~~
$$$$$$$$$$$$~~~~~~~~~~
$$$$$$$$$~~~~~~~~~~~~~~
$$$$$$$~~~~~~~~~~~~~~~~
~$$$$$~~~~~~~~~~~~~~~~~~
~$$~~~~~~~~~~~~~~~~~~~~~
$~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~
~~~~~~~~~~~~
~~~~~~~~~~
~~~~~~
~~~
Riding the Möbius strip
Being slightly disappointed with the coolness factor of a rotating Möbius strip I thought about other ways to emphasize the non-orientablity of the manifold. An often mentioned property of the Möbous strip is the fact that if one would walk along it one needs two laps to get back to the same configuration as before. After one lap we find ourself exaclty on the opposite site of where we started. This should look cool from the point of view of the person walking so I implemented that.
To do this instead of the rotations of the original donut code I translated and rotated the Möbius strip so that the camera seems to travel along the center circle perpendicular to the surface normal on that path. Given an angle $\alpha$ specifying the position on the circle on which one travels we transform the stip as follows:
$$ R_z\left(\tfrac{\alpha}{2}\right)\Big(R_y(-\alpha)\ R_x\left(\tfrac{\pi}{2}\right)\ m(x, y) - r_2\ e_1\Big), $$
where $R_x$ is the rotation matrix around the x-axis.
This is what it looks like:

The strip is slightly translucent in the near field of view because of the sampling size of the strip. Instead of picking a finer sampling size to fix this I decided to keep it because it makes it easier to see when one is on which “side” of the strip.
Actual code
The repository for the code is in my Gitlab. Feel free to use it in any way you like.