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!

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo πŸ“Šβœ¨

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay