DEV Community

Cover image for ๐Ÿฉ.๐Ÿ‡ (donut.c, but Emojicode)
Joe Skeen
Joe Skeen

Posted on

๐Ÿฉ.๐Ÿ‡ (donut.c, but Emojicode)

Inspired by the work of Evan Zhou, I determined that the world needed a donut.c variant with A LOT more sprinkles... thus ๐Ÿฉ.๐Ÿ‡ was born.

๐Ÿฉ.๐Ÿ‡ is written in Emojicode, a language that makes as much use of emoji as possible. I have used Emojicode for several years to solve Advent of Code coding challenges and have found it simultaneously frustrating and delightful to code in. Naturally porting donut.c to Emojicode was an enticing idea.

Coding Difficulties

It took me about 6 hours to port the original C code to Emojicode, as I ran into some snags along the way:

Compiler bug

In theory, these two lines from the original donut.c:

printf("\x1b[2J");
printf("\x1b[H"); 
Enter fullscreen mode Exit fullscreen mode

should translate to the following Emojicode:

๐Ÿ˜€๐Ÿ”คโŒe[2J๐Ÿ”คโ—
๐Ÿ˜€๐Ÿ”คโŒe[H๐Ÿ”คโ—
Enter fullscreen mode Exit fullscreen mode

Unfortunately the compiler complains about an unrecognized escape sequence. Thus, I wasn't able to include these lines (which clear the terminal and move the cursor to the top of the terminal). So if you run my program, it will just keep drawing more and more lines without clearing them. You need to size the terminal just right to avoid seeing more than one frame at once.

Shaping the code as a ๐Ÿฉ

Once the code was translated from C and working, the next challenge was to get the code shaped like a donut. Although Emojicode is not whitespace-sensitive, I discovered immediately that it wouldn't be as simple as putting line breaks every N characters.

Normally, code displayed in a monospace font has every column line up nicely, regardless of the relative width of the letter:

Hello
World
Enter fullscreen mode Exit fullscreen mode

But emoji aren't compatible with that paradigm. Emoji apparently are supposed to take up the width of two characters in monospace contexts, but depending on your browser, operating system, device, etc. that will vary. The following two lines contain four normal characters and three emoji characters, but do not line up (at least they don't for me, but maybe they do for you ๐Ÿคท):

0.0โžก๏ธ๐Ÿ–๏ธ๐Ÿ†•i
โ†ช๏ธ22โ–ถ๏ธy๐Ÿคy
Enter fullscreen mode Exit fullscreen mode

This lack of consistency made shaping the code very challenging as I couldn't use any ASCII donut templates to fill it in.

One more thing that caused a lot of difficulty with shaping the code was the one string literal in the code, used as a gradient for drawing darker and lighter "pixels" of the donut:

๐Ÿ”ค.,-~:;=!*#$@๐Ÿ”ค
Enter fullscreen mode Exit fullscreen mode

As Emojicode no longer has a string concatenation operator, I was constrained to keep all these characters from spanning multiple lines. This forced all the code above this string to be a certain size, which also determined (to some extent) the size of the code below it.

In the end, I was able to fit all the code into a donut shape, without adding any superfluous spaces or comments, which surprised me!

The final product

                ๐Ÿ๐Ÿ‡0.0โžก๏ธ๐Ÿ–๏ธ๐Ÿ†•A
            0.0โžก๏ธ๐Ÿ–๏ธ๐Ÿ†•B๐Ÿ”ค ๐Ÿ”คโžก๏ธ_๐Ÿ†•๐Ÿจ๐Ÿš
         ๐Ÿ’ฏ๐Ÿ†A 1760โ—โžก๏ธ๐Ÿ–๏ธ๐Ÿ†•z๐Ÿ†•๐Ÿจ๐Ÿš๐Ÿ”ก๐Ÿ†_
        1760โ—โžก๏ธ๐Ÿ–๏ธ๐Ÿ†•b๐ŸŽถ๐Ÿ”ค.,-~:;=!*#$@๐Ÿ”คโ—
     โžก๏ธL๐Ÿ”๐Ÿ‘๐Ÿ‡๐Ÿ”‚n๐Ÿ†•โฉ0 1760โ—๐Ÿ‡_โžก๏ธ๐Ÿฝb nโ—0.0
    โžก๏ธ๐Ÿฝz nโ—๐Ÿ‰0.0โžก๏ธ๐Ÿ–๏ธ๐Ÿ†•j๐Ÿ”jโ—€๏ธ6.28๐Ÿ‡0.0โžก๏ธ๐Ÿ–๏ธ๐Ÿ†•i๐Ÿ”
   iโ—€๏ธ6.28๐Ÿ‡๐Ÿ““iโ—โžก๏ธc๐Ÿ“•jโ—   โžก๏ธd๐Ÿ““Aโ—โžก๏ธe๐Ÿ““jโ—โžก๏ธf๐Ÿ“•A
  โ—โžก๏ธg dโž•2โžก๏ธh 1.0โž—          ๐Ÿคœcโœ–๏ธhโœ–๏ธeโž•fโœ–๏ธgโž•5๐Ÿค›
 โžก๏ธD๐Ÿ“•iโ—โžก๏ธl๐Ÿ“•Bโ—โžก๏ธm              ๐Ÿ““Bโ—โžก๏ธn cโœ–๏ธhโœ–๏ธgโž–fโœ–๏ธ
 eโžก๏ธt๐Ÿ”ข40.0โž•30.0โœ–๏ธ                Dโœ–๏ธ๐Ÿคœlโœ–๏ธhโœ–๏ธmโž–tโœ–๏ธn๐Ÿค›
 โ—โžก๏ธx๐Ÿ”ข12.0โž•15.0               โœ–๏ธDโœ–๏ธ๐Ÿคœlโœ–๏ธhโœ–๏ธnโž•tโœ–๏ธm๐Ÿค›
  โ—โžก๏ธy xโž•80โœ–๏ธyโžก๏ธo๐Ÿ”ข            8.0โœ–๏ธ๐Ÿคœ๐Ÿคœfโœ–๏ธeโž–cโœ–๏ธdโœ–๏ธg
   ๐Ÿค›โœ–๏ธmโž–cโœ–๏ธdโœ–๏ธeโž–fโœ–๏ธgโž–       lโœ–๏ธdโœ–๏ธn๐Ÿค›โ—โžก๏ธNโ†ช๏ธ22โ–ถ๏ธy๐Ÿคyโ–ถ๏ธ
    0๐Ÿคxโ–ถ๏ธ0๐Ÿค80โ–ถ๏ธx๐ŸคDโ–ถ๏ธ๐Ÿฝz   oโ—๐Ÿ‡Dโžก๏ธ๐Ÿฝz oโ—0โžก๏ธ๐Ÿ–๏ธ๐Ÿ†•
     Iโ†ช๏ธNโ–ถ๏ธ0๐Ÿ‡Nโžก๏ธ๐Ÿ–๏ธI๐Ÿ‰โ†ช๏ธIโ–ถ๏ธ๐Ÿ™Œ๐Ÿ“Lโ“๐Ÿ‡๐Ÿ“Lโ“โž–1โžก๏ธ๐Ÿ–๏ธI
      ๐Ÿ‰๐ŸฝL Iโ—โžก๏ธ๐Ÿฝb oโ—๐Ÿ‰iโฌ…๏ธโž•0.02๐Ÿ‰jโฌ…๏ธโž•0.07
         ๐Ÿ‰๐Ÿ”‚k๐Ÿ†•โฉ0 1761โ—๐Ÿ‡ โ†ช๏ธk๐Ÿšฎ80๐Ÿ™Œ0๐Ÿ‡
           ๐Ÿ˜€_โ—๐Ÿ‰๐Ÿ™…๐Ÿ‡๐Ÿ‘„๐Ÿฝb kโ—โ—๐Ÿ‰๐Ÿ‰
             Aโฌ…๏ธโž•0.04 Bโฌ…๏ธโž•0.02โฒ๐Ÿ‡
               ๐Ÿงต 10000 โ—๐Ÿ‰๐Ÿ‰ 
Enter fullscreen mode Exit fullscreen mode

To run this:

  • follow the Emojicode setup instructions for your OS
  • paste the code into a file (I use the filename ๐Ÿฉ.๐Ÿ‡, but you could use donut.emojic for the same results)
  • compile the code: emojicodec ๐Ÿฉ.๐Ÿ‡ (or emojicodec donut.emojic)
  • run the program: ./๐Ÿฉ (or ./donut)

๐Ÿฉ.๐Ÿ‡ at runtime

Conclusion

Overall, this was a pretty fun project, and I'm happy with the results. Go join Evan Zhou in his quest to compile a donut code file for as many languages as possible: https://github.com/EvanZhouDev/TheDonutProject

Top comments (0)

Some comments have been hidden by the post's author - find out more