
Infinite complexity in 4096 bytes - cageface
http://www.creativeapplications.net/windows/hartverdrahtet-infinite-complexity-in-4096-bytes
======
haberman
I'm pretty proud of my programming skills. I've worked in everything from
assembly to JavaScript, JIT compilers to websites to large-scale, fault-
tolerant distributed systems. etc. etc.

But demoscene programming is still the one thing that leaves me totally in
awe, feeling like I wouldn't even know where to start to achieve what these
guys pull off. Even if I could imagine fitting all those drawing and sound
generation routines into 4k, how on _earth_ would you script the whole thing
in that little space? How would you encode and execute the sequence of camera
paths, music events, and synchronize light flashes with the music? And make it
consistent in time, as opposed to depending on the speed of the CPU? I just
can't even imagine what the main loop would look like.

~~~
z303
For a general discussion of synchronisation, Martti Nurmikari gave a talk at
Assembly last year

[http://thedemoscene.tumblr.com/post/8659078065/martti-
nurmik...](http://thedemoscene.tumblr.com/post/8659078065/martti-nurmikari-
gives-a-talk-on-the-basics-of)

Alcatraz use an interesting system based on Clang and llvm to export all that
from Maya as source code

[http://thedemoscene.tumblr.com/post/22588846914/digi-
alcatra...](http://thedemoscene.tumblr.com/post/22588846914/digi-alcatraz-
talks-about-exporting-3d-scenes-from)

~~~
haberman
Excellent links, thanks!

------
vmind
Cool, but I think my favourite 4k demo is still Elevated, which is much less
obviously procedural. (<http://www.youtube.com/watch?v=_YWMGuh15nE>)

~~~
nkoren
Bloody hell, that's brilliant. That's really 4k?!? The intro gave me chills. I
wish the geometry were less obviously faceted, but the texturing is
astonishing.

Of course the OP is brilliant too. Kudos to all these guys!

~~~
z303
iq has a presentation on the techinques used

[http://iquilezles.org/www/material/function2009/function2009...](http://iquilezles.org/www/material/function2009/function2009.htm)

------
bane
Something to keep in mind is that these groups spend months building a world
in these 4096 bytes. These aren't weekend hack jobs. Near the end they may be
hacking off individual notes from the music, or letters from the credits to
fit within their byte budget.

Very little of modern programming can replicate what it was like to work on
old systems outside of these kinds of competitions.

For those interested in the music side of these productions, many of the
composers use this to write the music. <http://4klang.untergrund.net/>

------
ssdsa
If you are not familiar with 4k intros, you may wonder how things are
organized at the executable level to achieve this kind of packing-performance.
Probably the most important and essential aspect of 4k-64k intros is the
compressor. Have a look here: [http://code4k.blogspot.de/2010/12/crinkler-
secrets-4k-intro-...](http://code4k.blogspot.de/2010/12/crinkler-
secrets-4k-intro-executable.html)

~~~
ajtaylor
I've always wondered how they managed to pack so much information into so
small a space. Obviously it's all algorithms which generates everything at run
time. But still, it's very impressive!

------
__alexs
Or ~4096 bytes of Kolmogorov complexity...

~~~
Symmetry
Yes, its not literally "infinite complexity in 4096 bytes", but I think poetic
license is entirely justified here... it is a sort of visual poetry after all.

------
evincarofautumn
Well, colour me impressed.

Interesting side note: demos tend to use music with pentatonic (ambient) or
whole-tone (dreamy) scales. They’re easy to harmonise, which makes it easy to
procedurally generate decent-sounding music.

~~~
jlgreco
When watching demoscenes these days I find myself always waiting for the
dubstep 'drop'. Sadly I think modern music is starting to spoil this sort of
thing for me.

------
Eduard
Easily forgotten, a lot of today's demos' complexity lies behind API calls to
graphics drivers and OS system calls, whose implementations don't count to the
byte limit.

~~~
exDM69
Just like early PC 4k's used the BIOS/DOS interrupt routines which were not
counted either. And before that, there were all these custom purpose built
chips for doing graphics and audio synthesis.

When making 4k intros for Linux (may apply to other platforms) you have to do
your own startup and runtime linking code because otherwise the executable
will go over the limit before it does anything. Because of this, you will have
to minimize the amount of libraries you use and the amount of functions you
use. The name of every function you use must be included as a string in the
(uncompressed) binary. So even though you can use peripheral libraries, there
is an incentive to minimize the amount of library functions you use.

And what are the libraries that are used? You need to get something on the
screen, so many demos use SDL or similar, like this:

    
    
      SDL_Init(...);
      SDL_SetVideoMode(width, height, 32, SDL_FULL_SCREEN);
    

instead of:

    
    
      xor eax, eax
      mov al, 13h
      int 10h  ; I wonder if I still remember this correctly
    

The former is not much easier (or harder) than the latter but the latter is
simply impossible with a modern computer.

Then there's OpenGL and Direct3D, which are used to talk with the GPU. These
days a GPU is basically a method of drawing triangles really really fast. But
it draws only triangles and you have to program all the lighting and whatnot.
Then there are fancy shader tricks you can do, but they're not (a lot) easier
than it was when poking pixels directly to video memory.

It's arguably easier to do 3d graphics using a GPU than writing your own
triangle fillers and perspective correct texture mappers. But this is a double
edged sword. Getting shit done with triangles only is a constraint that did
not exist back in the pixel pushing days.

And finally, audio. Writing a software synth consumes quite a big chunk of
your byte budget. Back in the day, there were dedicated synth chips in
computers, from the SID to the OPL-3 in SoundBlasters and Ad-Libs. Programming
them was not super easy either, but I'd guess it takes a few bytes less than
writing a PCM-emitting synth from scratch and sending that data to the sound
output.

So what you say is correct, library implementations don't count to the byte
limit. But if your message is that it makes stuff easier and it was 2000% more
hardcore in the 1990's with DOS, I disagree.

~~~
raverbashing
Yeah, I think you got the int 10h right (not sure I remember this as well)

But then came VESA which was a little bit more complex and of course, screen
sizes bigger than a segment (ouch)

About audio, IMHO it's much easier now, dealing with those interrupt handlers
and dma controllers wasn't easy. Of course, once the library worked it was ok.

~~~
exDM69
> Yeah, I think you got the int 10h right (not sure I remember this as well)

10h is correct. The contents of ax register might not be. Is the graphics mode
(13h) supposed to be in the al or ah part? That I can't remember.

> But then came VESA which was a little bit more complex and of course, screen
> sizes bigger than a segment (ouch)

Yeah, early VESA Bios extensions were hairy. With VBE 2.0 you can get a simple
linear framebuffer with a high resolution quite easily.

> About audio, IMHO it's much easier now, dealing with those interrupt
> handlers and dma controllers wasn't easy. Of course, once the library worked
> it was ok.

Interrupt handlers and DMA controllers were used for PCM audio. I agree that
writing that stuff by hand was harder than doing it today with libraries. And
you'd still have to write the PCM-emitting synth.

But chip synths were generally programmed with simpler memory mapped I/O and
they did the actual audio synthesis for you, not only PCM output.

------
inoop
The technique used here is raymarching. Relevant thread on pouet:
<http://pouet.net/topic.php?which=7920>

~~~
dualogy
Yeah and there's many WebGL samples of this awesome technique:

<http://www.postronic.org/h3/pid65.html>

<http://y-alice.blogspot.com/2012/04/final-submission.html>

One pointlessly bouncy (but fun to make) experiment I ported from desktop GL
to WebGL a short while ago:

<http://glsl.heroku.com/e#2417>

Set quality to 4 or 8 as fast as you can unless you already got one of them
2014 GPUs.

That being said, none of those are 4K =)

------
josefonseca
Does this give anyone else the sense that with amazing processors we have
available that we're being really wasteful with these bloated apps we
currently have?

I mean if these guys are able to do this in 4K, what else could be done in
operating system terms if we achieved that same level of excellence?

~~~
Klinky
These demos rely on the OS to access sound & graphics, they could not reach
the fidelity they do without the OS hiding away much of the file size. You
could not do a 4K demo if you had to include the infrastructure to load a
modern graphics driver & OpenGL/DX libraries. They are also only small in
terms of package size. This demo for example uses about 550MB of RAM while
running(Win7x64).

~~~
spitfire
That's not true in the least. We used to do 4K's in dos. Which was a glorified
executable loader.

Once your program started executing you were on your own, graphics, sound,
memory management, everything. People still managed to get the first level of
descent into 4K.

~~~
Klinky
I didn't say you could not make a 4K demo at all. I said you could not make
one if you had to include an OS, drivers & DX/OpenGL libraries that most
modern 4K demos rely on. You could probably make something like this demo in
DOS, but it probably would look nowhere near as pretty.

My point was that modern 4K demos are still fun, but they should not be looked
at as though they are great examples of efficient uses of resources. You have
to watch out for Man on the Moon Syndrome where people start asking "Why can
we get infinite 3D fractal explorations in 4K of space, but Ruby's binary is
10MB!!?".

------
draakon
The lossless 60 fps high definition video capture is currently unavailable
(traffic limit). Any mirrors (or torrent would probably be a pretty good
idea)?

YouTube 1080p version seems to have pretty terrible quality.

~~~
jonknee
Somewhat humorous that the full resolution demo of a 4k intro is too large to
handle on the server. Just post the source

------
winestock
Not only are there 4-kilobyte demos, there are also 256- _byte_ demos.

<http://dang.posterous.com/256-byte-demos>

[http://www.pouet.net/search.php?what=256+bytes&type=prod...](http://www.pouet.net/search.php?what=256+bytes&type=prod&x=0&y=0)

------
degenerate
I once spent hours looking for an internet archive or community of demo scene
files / artists. There doesn't seem to be one out there in the eyes of google.
Can anyone familiar with this art form please provide links to your your
underground hangout? :)

~~~
sp332
This is a very thorough list of the most famous (read:best) and most
influential demos: <https://news.ycombinator.com/item?id=3840830>

------
bane
The entire 4k competition from that party is here

<http://www.youtube.com/watch?v=bdG-5Fhnx-I>

well worth the watch...

------
jacquesm
German hartverdrahtet -> hardwired / hardcoded but also 'wired hearts' (the
opening shot and the primitive the scene appears to be made out of)

~~~
markerdmann
"Herz" is the German word for heart. Do you mean that "hart" sounds like the
English word "heart"?

~~~
jacquesm
Yes, it looked like a play on words. In dutch (halfway between English and
German) it literally means heart.

------
Voltage
Here's my first 4k production: <http://www.youtube.com/watch?v=sBcwQCBpEiE>

If you want to play with this type of code right now in your browser, check
this out... <http://glsl.heroku.com/e#2431.0>

------
pnathan
Note that if you crave this kind of world of limited resources and ingenuity
for packing things very small, it still exists in a professional setting in
hard real-time embedded systems.

I heard a story at my company about fixing a bug a couple years ago. Memory
was full, so in order to do that, the engineers rewrote the UI messages to
allow the extra instructions to fit into memory.

------
aerique
What a piece of art!

------
10098
it's things like this that remind me how sucky my "skills" actually are

------
pjmlp
Demoscene!

------
Iwaan
I was an intern at a game company last year. I showed the CEO some of the
stuff that is going on in the demoscene. He got really worried and told me to
not show that to any of his staff. He was afraid that it intimidates his
highly paid coders and designers. I found that rather disturbing. How are you
going to kill Hollywood if you are afraid of algorithms?

~~~
muyuu
Any game coder worth his salt knows fractals. Many veterans from the demoscene
ended up in the game industry at some point. In the 90s most wizkids dreamt of
living off making games, and many demosceners made intros to cracked games.

Good game coders like Carmack have little to feel intimidated about.

~~~
aptwebapps
Your point is good but saying that Carmack shouldn't feel intimidated is
probably not helpful. ;)

