Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by a1k0n on Wednesday October 21, 2015 @09:05PM
(#10429886)
Speaking of crazy ascii company logo animations, I never got a chance to golf these down, but I made some with color and signed distance field ray marching:
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by userbinator on Wednesday October 21, 2015 @10:25PM
(#10430084)
I think raymarching is an extremely elegant way to make complex scenes fit into a tiny amount of space. These are my favourite articles on raymarching because it shows just how compact they can be - a single mathematical equation:
Edit: The description for the "bridge" scene is interesting: "This is a sketch really, but it never got completed, due to the lack of artistic appealing of the image." I don't know if it's his extreme humility, but I think it wouldn't be overexaggerating if I said it's one of the best scenes on that page.
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by anon4 on Thursday October 22, 2015 @07:16AM
(#10431530)
One more crazy thing you can do with raymarching - smoothly twine any shape into any other shape. Take any two signed distance fields, say they're defined by the functions dist0(p) and dist1(p). Then you can do
dist(p, t) = (1-t)*dist0(p) + t*dist1(p)
T doesn't have to be time-based, it can be space-based, so you have a shape that's a cylinder on the bottom and a large sphere on top and here's a mushroom https://www.shadertoy.com/view/lsSXWc
Edit: I have a very strong feeling that in most cases the resulting function isn't a "proper" distance field, but you can still raymarch through it normally.
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by cantrevealname on Wednesday October 21, 2015 @08:39PM
(#10429813)
You can do super dense mathematical code in the ancient APL programming language[1]. I wonder how even more tiny this program could get at the hands of an APL expert if any still exist.
Here are some complete APL programs[2] to give a flavor of just how dense it can get:
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by a1k0n on Thursday October 22, 2015 @01:22AM
(#10430528)
I am a big fan of viznut also, and took the liberty of translating this into Javascript so we can all hear it without trying to find a /dev/dsp analog (I used ./viznut | sox -t raw -e unsigned -b 8 -r 8000 - -d):
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by Rotten194 on Wednesday October 21, 2015 @08:49PM
(#10429843)
You have to pipe it into an audio player (traditionally that was /dev/dsp IIRC but I don't think that's a thing anymore). aplay should work with the right flags.
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by onion2k on Thursday October 22, 2015 @04:55AM
(#10431136)
That's very cool.
You can do something similar using Chrome's console output. There used to be an intro that worked by rendering a canvas as ascii but it's broken in newer Chrome - http://sandbox.photonstorm.com/console.log/ (it may work for other people). I figured out how it works and made a little animation to explore the principle - http://ooer.com/console/i.html (You'll need to change the height of the console to fit 16 lines of output)
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by lopatin on Wednesday October 21, 2015 @07:24PM
(#10429540)
The lines don't seem to be over 80 chars long. It's code golf so it's still going to be hard to read but the 80 char lines are acceptable in most code bases.
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by cgriswald on Wednesday October 21, 2015 @08:52PM
(#10429855)
"Lines of C" is an arbitrary and relatively meaningless metric. Even number of characters would have more meaning and perhaps be more interesting than number of 'lines'. Unless you define a "line" as 80 characters (in which case you really have a rough estimation of character count).
Nonetheless, these things are fun and often novel, both in what they accomplish and how they accomplish it. I like looking at them (not always reading them) for many of the same reasons I like looking at brainfuck or perl code. Plus, you know, compression. ;)
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by oneeyedpigeon on Wednesday October 21, 2015 @07:28PM
(#10429559)
Come on, were you really expecting that animation to be done in, like, 6 statements? Even once you understand the current of compression ratios minification of c code can achieve, this is still impressive. I bet the 'uncompressed' version of this code would still be interesting. Actually - here's where I kinda agree with you - it would probably be much more interesting, since we'd be able to understand it more readily.
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by david-given on Thursday October 22, 2015 @05:10AM
(#10431186)
This kind of game was common in BBC Basic, way back in the 80s and 90s. It was limited to 255-ish tokens per line. (Excitingly, the keyboard buffer was 255 characters, but each keyword was tokenised to a single byte. Which meant that with trickery it was possible to get lines of Basic longer than it was actually possible to edit.)
At least one of the computer magazines of the day had a regular column of one-line BBC Basic programs sent in by readers. There were some quite good games.
Alas, I suspect that most of these have been lost to history, but here's a one-line Tetris:
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by userbinator on Wednesday October 21, 2015 @10:22PM
(#10430075)
Even if you run a formatter over the source and rename the variables to some longer names, these tiny programs are still algorithmically impressive. Otherwise they'd be nearly trivial to generate from bigger ones by running minifiers on them.
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by agumonkey on Wednesday October 21, 2015 @10:53PM
(#10430169)
Many where like minimally functioning PoC. When I thought about raytracing I always assumed large code base. Watching the bare principle in a snippet is pretty awesome.
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by agumonkey on Wednesday October 21, 2015 @10:51PM
(#10430163)
Sometimes it's more than lexical minification though, you also learn a bit about the grammar and how to express something in fewer bits. Even tiny design tricks, like encoding binary as chars to express data.
Re:Yahoo Logo ASCII Animation in 462 bytes of C (2011)
by a1k0n on Thursday October 22, 2015 @01:26AM
(#10430538)
FWIW, most of this code is actually contained inside for loop expressions, since you can chain them together with commas and get away without using any braces. Once that's done it's hard to even count "lines".
https://github.com/a1k0n/asciitracing
http://iquilezles.org/www/articles/distfunctions/distfunctio...
http://iquilezles.org/www/articles/raymarchingdf/raymarching...
Edit: The description for the "bridge" scene is interesting: "This is a sketch really, but it never got completed, due to the lack of artistic appealing of the image." I don't know if it's his extreme humility, but I think it wouldn't be overexaggerating if I said it's one of the best scenes on that page.
Edit: I have a very strong feeling that in most cases the resulting function isn't a "proper" distance field, but you can still raymarch through it normally.
Here are some complete APL programs[2] to give a flavor of just how dense it can get:
Sum integers from 1 to 100:
Find all primes from 2 to a given number R: Play Conway's Game of Life: [1] https://en.wikipedia.org/wiki/APL_%28programming_language%29[2] http://www.vaxman.de/publications/apl_slides.pdf
https://jsbin.com/tazeyoqoci/edit?html,output
Amazing work.
< i=9 99;
> i=999;
Garbage is displayed when I execute the code.
You can do something similar using Chrome's console output. There used to be an intro that worked by rendering a canvas as ascii but it's broken in newer Chrome - http://sandbox.photonstorm.com/console.log/ (it may work for other people). I figured out how it works and made a little animation to explore the principle - http://ooer.com/console/i.html (You'll need to change the height of the console to fit 16 lines of output)
http://mnml.is/hn/jslinux.jpg
Then you look at it and realize that a "line" is actually 20 different statements minified.
I found jquery implemented in a single line![1]
[1] https://jquery.com/download/
Nonetheless, these things are fun and often novel, both in what they accomplish and how they accomplish it. I like looking at them (not always reading them) for many of the same reasons I like looking at brainfuck or perl code. Plus, you know, compression. ;)
https://gist.github.com/a1k0n/15f6cc2fc9428d6fd197
At least one of the computer magazines of the day had a regular column of one-line BBC Basic programs sent in by readers. There were some quite good games.
Alas, I suspect that most of these have been lost to history, but here's a one-line Tetris:
http://survex.com/~olly/rheolism/dsm_rheolism/> Yahoo Logo ASCII Animation in one line of C (2011)
What's the difference between six lines of C and one line of C?
The problem with using those for code metrics is that many systems don't require separators, like `if`, `for` and friends