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");
should translate to the following Emojicode:
๐๐คโe[2J๐คโ
๐๐คโe[H๐คโ
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
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
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:
๐ค.,-~:;=!*#$@๐ค
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 โ๐๐
To run this:
- follow the Emojicode setup instructions for your OS
- paste the code into a file (I use the filename
๐ฉ.๐
, but you could usedonut.emojic
for the same results) - compile the code:
emojicodec ๐ฉ.๐
(oremojicodec donut.emojic
) - run the program:
./๐ฉ
(or./donut
)
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