Hacker News new | past | comments | ask | show | jobs | submit login

I'm totally impressed that

b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0];

is allowed in C.




I had no idea that printing something like "\x1b[2J\x1b[H" can clear the screen - with a bit of googling I found out that this is not that unusual a command, but it still took a little reading to figure it out! [1]

Looks like the rest of the code is for generating the donut. Quite a bit of math involved - too much for a sunday morning to look into and attempt to decipher!

[1] http://www.codeguru.com/forum/archive/index.php/t-311110.htm... explains it quite well:

Those are so-called ANSI terminal escape sequences - there is a whole list of them. Hex 1B is the escape character, the characters after that determine the action (clearing the screen, changin text color, moving the cursor etc.) Well, and "[2J" is the sequence for clearing the screen.


<ESC>[H ("home") moves the cursor to the upper-left hand corner, so I initially clear the screen and then use "home" to do the animation.

An alternative method to animate ascii stuff, used in the Yahoo logo, is just to cursor-up 25 lines (or whatever) with <ESC>[25A between frames. That way it doesn't have to clear the screen and you can see your command history, etc.


It's not at all complicated. Most of it is a string literal.

This is an assignment to index o of the array b

    b[0] =
this is the string

     ".,-~:;=!*#$@"
and this is indexing into the string literal with N, or 0 if N is less than 0.

     [N > 0 ? N : 0]




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: