# I ported the classic ASCII Donut to Fortran

**URL:** <https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173>\
**Category:** Announcements\
**Created:** [October 27, 2021, 4:13am UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173 "2021-10-27T04:13:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShrirajHegde](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@ShrirajHegde](https://fortran-lang.discourse.group/u/ShrirajHegde)\
**Post date:** [October 27, 2021, 4:13am UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/1 "2021-10-27T04:13:48Z")

</div>

Link to the GitHub repo : [ASCII-Donut-Fortran](https://github.com/ShrirajHegde/ASCII-Donut-Fortran)

![donut](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/1X/08534e1b011a6a3f1ef94cdd19fff0cd32decc1d.gif)

Suggestions and improvements highly welcome 🙂

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [October 27, 2021, 7:28am UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/2 "2021-10-27T07:28:22Z")

</div>

That looks very nice - and the code is concise. I do have a number of remarks about it, but I will first take a closer look 🙂

---

<div class="post-metadata">

**Author:** ![interkosmos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/interkosmos/32/296_2.png) [@interkosmos](https://fortran-lang.discourse.group/u/interkosmos)\
**Post date:** [October 27, 2021, 9:25am UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/3 "2021-10-27T09:25:37Z")

</div>

On a first look, it seems that your ANSI escape sequences lack the escape character (27):

```fortran
write(*,"(A)",advance="no")"[2J"
! […]
write(*,"(A)",advance="no")"[d"

```

Probably better to set the character explicitly:

```fortran
write (*, '(a1, "[2J")', advance='no') char(27)
! […]
write (*, '(a1, "[d")', advance='no') char(27)

```

---

<div class="post-metadata">

**Author:** ![ShrirajHegde](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@ShrirajHegde](https://fortran-lang.discourse.group/u/ShrirajHegde)\
**Post date:** [October 27, 2021, 10:28am UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/4 "2021-10-27T10:28:54Z")

</div>

I directly used the escape character directly to avoid a function call in the loops. The escape character looks like a square or like this ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/1X/668046abd1e889f9be0065044d09da2f6a2fa01e.png)

Another option is defining a variable and using that.

Please take a look at the [latest commit.](https://github.com/ShrirajHegde/ASCII-Donut-FORTRAN/commit/09b8d1b3b7c927a1f97517fb53c73417c9a4fda1)

Implemented like this.

```auto
CHARACTER::ESC=achar(27)
! […]
write(*,"(A)",advance="no")ESC//"[2J"

```

---

<div class="post-metadata">

**Author:** ![alozada](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/alozada/32/298_2.png) [@alozada](https://fortran-lang.discourse.group/u/alozada)\
**Post date:** [October 27, 2021, 12:00pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/5 "2021-10-27T12:00:04Z")

</div>

> [@ShrirajHegde](#):
>
> Suggestions and improvements highly welcome

Just a little color

Ansi colors 31 and 32

![colors_donut2](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/1X/14c33fa266bd8992231aa510ccb7b446c01c367f.gif)

---

<div class="post-metadata">

**Author:** ![ShrirajHegde](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@ShrirajHegde](https://fortran-lang.discourse.group/u/ShrirajHegde)\
**Post date:** [October 27, 2021, 12:54pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/6 "2021-10-27T12:54:46Z")

</div>

Good idea, Even I thought of color.

But using just two colors will make it lose the luminance detail because the “fill” from different characters become not very apparent. At least for me, I see less luminance detail in the two colored version (I partially close my eye to make each character blurry and blend in).

To preserve or even enhance the luminance detail, we could use a gradient from color A to color B, and these characters for every gradient resulting both a single color and the “fill” giving the luminance detail. Implementation seems pretty straight forward too since in line 41, 8 is multiplied to distribute luminance values from 1st character to 12th character. If we have N resolution, then we can distribute that accordingly and get essentially what constitutes as “HDR”

That being said, a bit off-topic, but I have implemented some more features in this [python version](https://github.com/ShrirajHegde/donut/blob/main/donut.py) (which I modified)

Features include, auto resize on terminal resize/font size change, show “FPS”, Auto adjust speed so that scale doesn’t change the animation speed etc. Trying first on python version as a proof of concept would be nice idea.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [October 27, 2021, 2:01pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/7 "2021-10-27T14:01:45Z")

</div>

@ShrirajHegde welcome to the forum!

Nice example. I have one suggestion: rename the repository from `ASCII-Donut-FORTRAN` to `ASCII-Donut-Fortran`. 🙂

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [October 27, 2021, 2:16pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/8 "2021-10-27T14:16:47Z")

</div>

The animation above also appears on the readme.md, and its source is a file gif\scale-1.gif . How is such a file created from a program that writes text to the screen?

---

<div class="post-metadata">

**Author:** ![ShrirajHegde](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@ShrirajHegde](https://fortran-lang.discourse.group/u/ShrirajHegde)\
**Post date:** [October 27, 2021, 2:26pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/9 "2021-10-27T14:26:30Z")

</div>

It’s just OBS screen-record of the terminal and then extract frames with FFmpeg, Then I used [https://gif.ski/](https://gif.ski/) to convert those frames to a good quality GIF without artifacts.

GitHub should support using silent MP4s as GIFs like other platforms. GIF is too inferior for 2021.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [October 27, 2021, 2:27pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/10 "2021-10-27T14:27:18Z")

</div>

I think GitHub supports videos.

---

<div class="post-metadata">

**Author:** ![ShrirajHegde](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@ShrirajHegde](https://fortran-lang.discourse.group/u/ShrirajHegde)\
**Post date:** [October 27, 2021, 2:28pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/11 "2021-10-27T14:28:30Z")

</div>

I had named it `ASCII-Donut-Fortran` itself, but for some reason [https://languagetool.org/](https://languagetool.org/) insisted it should be `ASCII-Donut-FORTRAN`

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [October 27, 2021, 2:32pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/12 "2021-10-27T14:32:20Z")

</div>

I think [https://languagetool.org/](https://languagetool.org/) needs to improve…

---

<div class="post-metadata">

**Author:** ![ShrirajHegde](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@ShrirajHegde](https://fortran-lang.discourse.group/u/ShrirajHegde)\
**Post date:** [October 27, 2021, 2:33pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/13 "2021-10-27T14:33:47Z")

</div>

Can you confirm or any reference/example? I have tried placing MP4 and MKV but no luck.

---

<div class="post-metadata">

**Author:** ![ShrirajHegde](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@ShrirajHegde](https://fortran-lang.discourse.group/u/ShrirajHegde)\
**Post date:** [October 27, 2021, 2:34pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/14 "2021-10-27T14:34:42Z")

</div>

Thanks for the suggestion, Repository renamed.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [October 27, 2021, 3:06pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/15 "2021-10-27T15:06:14Z")

</div>

> [@ShrirajHegde](#):
>
> Can you confirm or any reference/example? I have tried placing MP4 and MKV but no luck.

> **[You can now upload videos to comments and gists on GitHub - MSPoweruser](https://mspoweruser.com/upload-videos-comments-gists-on-github/)**
>
> View Survey Close surveyXIs Copilot the best AI companion out there? Help us find out by answering a couple of quick questions!Let's startMicrosoft Copilot Survey GitHub yesterday announced the ability for users to upload videos to gist comments and...

I tested uploading mp4 into a github comment and it shows. I can’t remember which comment I did it in now.

---

<div class="post-metadata">

**Author:** ![ShrirajHegde](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@ShrirajHegde](https://fortran-lang.discourse.group/u/ShrirajHegde)\
**Post date:** [October 27, 2021, 3:10pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/16 "2021-10-27T15:10:11Z")

</div>

Nice, if they could play silent MP4s as GIFs (autoplay and loop support) it would be great. But this is better than nothing.

No other major platforms use GIFs, they just loop MP4s, Sometimes MP4s even with audio but muted.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [October 27, 2021, 3:28pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/17 "2021-10-27T15:28:57Z")

</div>

Welcome @ShrirajHegde and thanks for sharing it. I just posted it on our Twitter:

> <https://twitter.com/fortranlang/status/1453382940117938177>

---

<div class="post-metadata">

**Author:** ![ShrirajHegde](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@ShrirajHegde](https://fortran-lang.discourse.group/u/ShrirajHegde)\
**Post date:** [October 27, 2021, 6:06pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/18 "2021-10-27T18:06:16Z")

</div>

Thanks a lot ! I saw it !

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [October 28, 2021, 10:06am UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/19 "2021-10-28T10:06:00Z")

</div>

Just a few remarks on the style. Of course in a program like this the understanding of the code is secondary, but in general, just my opinion:

- Do not use variable names like i and j for REAL variables. People are used to using these as index variables, so automatically assume they are integers. LIkewise, the other way around for names like x and y
- Make clear that a literal value is a REAL value: instead of 4, use 4.0 (or 4.)
- CHARACTER :: ATABLE\*12 - make that CHARACTER(LEN=12) :: ATABLE
- A variable name like “o” can easily be mistaken for 0 (not in the font used by Github, but in many others). Similarly, “l”

But, like I said, that holds in general. In a compact program like this, the result counts 🙂

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [October 28, 2021, 1:32pm UTC](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173/20 "2021-10-28T13:32:52Z")

</div>

> [@Arjen](#):
>
> Make clear that a literal value is a REAL value: instead of 4, use 4.0 (or 4.)

I personally usually prefer integers if it is an integer assigned to a real.

I agree with all your other points.

[Next page](https://fortran-lang.discourse.group/t/i-ported-the-classic-ascii-donut-to-fortran/2173.md?page=2)
