DEV Community

Cover image for donut.c, but in Pascal
Joe Skeen
Joe Skeen

Posted on

donut.c, but in Pascal

Back in the mid-90s, as an eight-year-old child, I was very interested in computers. My father (also Joe Skeen) was a computer programmer and technician so I was lucky enough to have a computer in my home. Wanting to create cool programs, I started teaching myself Borland Delphi and I created a handful of simple games. Soon afterwards, the Internet started being a thing and I taught myself HTML. As I progressed in my self-education, I'd teach myself PHP, CSS, JS, and other languages before starting college.

I recently came across Evan Zhou's Donut Project, and felt it fitting to contribute code from the language of my personal development origin.

Writing the Code

My first challenge was to get some way of compiling Pascal. Back in the day I would have installed Borland Delphi, but now I'm daily-driving Linux which is not what Delphi was made for. (I'm unsure whether RAD Studio, Delphi's successor, even works on Linux, but felt like too much to try to set up for such a simple project.) I instead opted to develop in an online Pascal compiler.

The first 10-15 minutes of porting over the original donut.c to Pascal was difficult, as I had to remember all the syntax I had long forgotten. After that, though, it went pretty quickly, with the working Pascal implementation in donut shape within about two hours.

The Final Product

Run this code online: https://onlinegdb.com/NOnW4xKa4

                   PROGRAM Donut
              ;USES CRT;VAR k,x,y,o,r
           :Integer;A,B,i,j,c,d,e,f,g,h,
        q,l,m,n,t:Single; z:ARRAY[0..1759]
      OF Single;p:ARRAY[0..1759]OF Char;BEGIN
     A:=0; B:=0; clrscr; WHILE True DO BEGIN//
    FillChar(z,SizeOf(z),0);FillChar(p,SizeOf(p
   ),' ');j:=0;WHILE j<6.28 DO BEGIN i:=0; WHILE
  i<6.28 DO BEGIN c             :=sin(i);d:=cos(j
 ); e:=sin(A);f:=                 sin(j);g:=cos(A)
 ;h:=d+2;q:=1/(                     c*h*e+f*g+5);l
 := cos(i); m:=                     cos(B);n:=sin(
 B);t:=c*h*g-f*                     e;x:=Trunc(40+
 30*q*(l*h*m-t*                     n));y:= Trunc(
 12+15*q*(l*h*n                     +t*m));o:=x+80
 *y;r:=Trunc(8*((                 f*e-c*d*g)*m-c*d
  *e-f*g-l*d*n));IF             (22>y)AND(y>0)AND
   (x>0)AND(80>x)AND(q>z[o]) THEN BEGIN z[o]:=q;
    IF r>0 THEN p[o]:='.,-~:;=!*#$@'[r] ELSE p
     [o]:='.';END;i:=i+0.02;END;j:=j+0.07;END
      ;gotoxy(1,1);FOR k:=0 TO 1760 DO BEGIN
        IF k MOD 80  = 0 THEN writeln ELSE
           write(p[k]); END; A:=A+0.04;
               B:=B+0.02;Delay(5);{
                   }END; END.//
Enter fullscreen mode Exit fullscreen mode

I hope you enjoy this and take a look at all the other Donut Project submissions!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay