

Real pixel coding (2011) - dshankar
http://www.iquilezles.org/blog/?p=1426

======
jgrahamc
Back when I was coding on the Sharp MZ-80K ([http://blog.jgc.org/2009/08/in-
which-i-switch-on-30-year-old...](http://blog.jgc.org/2009/08/in-which-i-
switch-on-30-year-old.html)) we used to write code by typing it directly onto
the screen. The screen was just directly memory mapped with each character on
screen being a single byte. And the machine had the complete character set
available from its (odd) keyboard.

The program would be written in assembly, converted by hand to hex and then
each hex byte found in the character map and typed in. It was then possible to
CALL the start of screen memory to run the program.

~~~
femto
A useful debugging technique on the VZ200 was to locate the stack in video
memory. The display would be a mass of snow when the program was running,
since the CPU activity left hardly any cycles for the video controller to
access screen RAM, but when the program crashed its state could be read
directly off the screen.

~~~
jgrahamc
Nice. I've used this type of technique in other situations where very high-
speed debug output is needed.

At one job we had a machine code ring buffer implementation that could be
called via a software interrupt (INT 3 I believe with a single character in
AL) to write a single byte of debug information. This could be used when
tracing a program's execution. When the program crashed the ring buffer could
be examined using a system debugger (typically Soft-ICE) to see what state it
was in. Very useful when it was critical to get tracing information in a way
that had minimal timing impact.

~~~
femto
I'm using this exact technique in my daily work right now! :-). It's an
embedded DSP doing real-time signal processing for digital radio, and the
technique you describe allows the execution flow leading up to a crash to be
determined, without the timing jitter introduced by the "real" debugger.

------
Erwin
There's this esoteric programming language:
<http://www.dangermouse.net/esoteric/piet.html>

where the source code are images similar to works of Piet Mondrian.

And there's ColorForth where the colors replace some of the punctuation
normally used in Forth: <http://www.colorforth.com/cf.htm> \-- this (seems?)
more serious.

------
libovness
"Kill two births with one stone" is the most unfortunate malapropism I've ever
seen

~~~
javajosh
And yet somehow appropriate to the unusualness of this technique. And, from a
Google perspective, it's likely that you'll be able to reference this post
with that phrase for all time.

~~~
libovness
Sure, if attracting anti-abortionists to your website is a good thing...

------
shurcooL
70% of the video he spends just manually copying bytes from a pre-written
compiled and likely compressed source (off screen to the right). It's just
dressed up (for the general public that find this stuff impressive because
they don't really understand what's going on).

Not to downplay it here, I'm just describing what's going on. This is
basically a small nice looking demo.

~~~
algorias
No compression of any type involved. He writes machine code and saves it to a
.com file, which can directly be executed. The first thing it does is activate
mode 13h, which gives direct access for drawing to the screen. The surprising
thing here is that both these hacks are still supported by various versions of
windows. They really used to take backwards compatibility seriously.

------
arocks
It took me several rereads to understand that what the author was referring to
in the first few lines is a demo[1] say the 4K intro, where a few bytes in
assembly language can create some interesting graphics often accompanied by
music; often conveying a concept.

[1]: <http://en.wikipedia.org/wiki/Demoscene>

~~~
Jare
For reference, this is one of Iñigo's finest creations:
<http://www.youtube.com/watch?v=jB0vBmiTr6o>

~~~
scoot
In 4K? That's obscene! There's link in the video notes to a description of how
it was created which makes for an interesting read:
[http://www.iquilezles.org/www/material/function2009/function...](http://www.iquilezles.org/www/material/function2009/function2009.pdf)

~~~
CountHackulus
iq is very well known in the demoscene. He's one of the greatest and most
creative coders that there's ever been.

------
alexkus
I remember being impressed by a friend at University who would do:-

copy CON: reboot.com

and then enter 8 or 9 bytes (some via ALT+keypad) all from memory.

(There are ways to do it in just 2 bytes I believe, this isn't about
reboot.com golf anyway...)

~~~
thristian
See also the EICAR Standard Anti-Virus Test File[0], which is a valid MS-DOS
.com file composed of only printable ASCII characters. Granted, its output
isn't nearly as pretty as the one in the video, but it's still a neat trick.

[0]: <https://en.wikipedia.org/wiki/EICAR_test_file>

------
6ren
Wow, 32×32 doesn't sound like much to me, but it's actually 1024 pixels. If
you had 4 bytes per pixel, that's 4K - you can do quite a lot with that, even
in java: <http://www.java4k.com>

~~~
asmosoinio
His image was 9x9 pixels, not 32x32. So 324 bytes.

------
edlinfan
A great reminder that code is data, and data code.

Now I want to see how all my programs look as bitmapped images... brb.

~~~
shurcooL
Hopefully it will look mostly like random noise, without many patterns. That
would indicate compressed information without much repetition. If you see lots
of regular patterns, perhaps that means refactoring is in order to maintain
DRYness.

Hmm, curious if this visualization would actually work to spot duplicated
code.

~~~
algorias
Hopefully it won't actually. Most languages are not designed for compactness
of source code, and most forms of factoring will produce fairly noticeable
patterns; e.g. lots of funcion declarations.

~~~
shurcooL
True. One would have to first reduce the natural duplication/patterns that
come with the language (i.e. function declarations, etc.) so that only the
meaningful user code is left, before such analysis would be useful.

------
Aardwolf
"during the last 5 years i’ve been explaining people that it takes less space
to write a 3 minutes HD animated video and music clip than than it takes to
store a 32×32 pixel icon."

This sounds so wrong. This sentence makes it sound as if any 3 minutes HD
video has smaller filesize than a 32x32 pixel icon. Of course people won't
believe you if you use that wording.

I assume what you mean to say is, it is possible to create SOME 3 minute video
with music that is smaller than SOME 32x32 pixel icon.

E.g. if you store the 32x32 pixel icon in some XML format that describes every
single pixel color component, and the video is plain white with some bleep
music :p

~~~
jasonwatkinspdx
Except for the next fucking sentence where he explains it's about algorithmic
generation not arbitrary compression. He's assuming his readers have a brain.
That might be a false assumption.

~~~
Jabbles
Couldn't you just apply the same techniques to generate 1024 pixels in less
than the filesize it takes to generate a video?

If he's having trouble explaining it to people, it's because he's not wording
it correctly. And if he's wording it correctly he should use the same,
correct, understandable wording to tell us.

~~~
zeidrich
Yeah. He's not creating a video, he's creating a program that displays a
video. If you create a 320x240 program that animation and call it a video, you
might as well call every frame an array of 300 16x16 icons.

The point is pretty cool though, algorithmic compression is pretty awesome,
especially when you don't have to conform to any particular end result. A
fresh Minecraft world is a 240k jar file used as a decompression tool, and the
data is a single integer (the seed). In the end the result is some 9 million
times the surface area of the Earth.

However, start modifying that world and the data needed to store it balloons.
Make a world that accurately mimics the surface of just Iceland and you're
going to be looking at a pretty large file.

Accept a world that's a bit of simplex noise and Brownian motion and let
yourself be awed. Make a video of rotating around a fractal made from a simple
formula - that looks cool. Try and compress a video of your daughter's first
steps and you'll get something significantly larger than an icon. Especially
an icon that's at least run-length encoded.

~~~
nawitus
There's no real computer science distinction between a program which displays
a video and a video. You can always create a video format which (optionally)
can read some bytecode and run it in a virtual machine. There are Turing
complete font formats you know.

------
smosher
<http://esolangs.org/wiki/Piet>

~~~
ygra
It's not Piet, though.

But granted, initially I assumed the article would be about that, but the
colours give it away that it's not. Well, that, and the description of what
he's doing.

~~~
smosher
You're right. I was disappointed when I found out what it was, but I didn't
come to complain about it. I just thought people might like to see something a
little more in line with the title.

------
lucb1e
I've always been wanting to do this, but never got to it. Never thought of the
.raw format without header, which probably makes it much easier. It still
looks very impressive though, nice job!

------
kaoD
I knew this was iq's even before looking at the domain name :) Great spanish
talent.

Don't forget checking his productions with RGBA!
<http://pouet.net/groups.php?which=697>

------
xhrpost
Pretty awesome. Correct me if I'm wrong but I'm fairly certain this won't work
in Windows 7 - 64 Bit as 16-bit COM applications are no longer supported. I've
tried to go back and get my simple COM programs from Assembly class at college
to work but no luck. It was just really simple to do a very basic program
using simple DOS function calls. Anyone know a simple way to do basic assembly
programming in 64 Bit windows OSs? I tried was unsuccessful in getting a
linker working.

~~~
klipt
You could presumably run it in DOSBox.

------
cthackers
I'm sure this is very possible. There are only few opcodes for a x86 real mode
com to use and if you look at the demoscene and see what those guys can
do...this is not even that impressive :) Steve Wozniak wrote BASIC for the
Apple computer in binary.

------
jztein
This is cool. Could somebody please explain how this works? From what I can
currently guess, the .midi image encoding with the 2D array of color values,
when changed to an .com executable becomes assembly code that generates
graphics? Thanks.

~~~
cthackers
Initially is a 2d array but when saved without a image header to give it width
and height (and other meta data) it becomes just an array of bytes. A color is
encoded in 3 bytes, so with each pixel he can write one, two or three opcodes.
If you google opcode tables you'll find plenty of examples of how assembly
instructions are encoded in bytes.

For example (this is 16 bit but for the sake of demonstration) byte A1
(10100001) means ADD AX, BX. 101(add)00(ax)001(bx).

[Edit]

Found a cool image showing x86 opcodes. <http://i.imgur.com/69Lli.png>

And even a cooler one with windows exe description (not DOS .com as he used)
<http://i.imgur.com/tnUca.jpg> Look at the right side of the image where it
sais x86 Assembly where it colors and explains each byte. His .com was only
that part since .com didn't need headers and imports and it was just code.

~~~
jztein
Thanks for the explanation and images cthackers:) I guess that the tunnel is
an infinite loop from JMPs. I think I'll try to make one.

------
islon
Congratulations, you just gave syntax highlighting a whole new meaning!

------
9999
A little known company had this same idea in the mid 90s. I believe it
languished in obscurity and then died after an unfortunate takeover. The
company was Macromedia, the product was Flash.

------
tehwalrus
final vid needs Doctor Who music! hmm... I wonder how simple a MIDI file you
could make to play something like that tune... and what _that_ would look like
as a RAW bitmap...

~~~
dave1010uk
You can generate music with algorithms too. I came across this a while ago:

    
    
        echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay
    

The generated a.out is 8.5kB for me though.

~~~
leephillips
That sounds better than most of the pop music out there. Amusing demonstration
of ... something!

~~~
zxcdw
Demonstration of using very few bytes of data to generate art. The same
snippet of code can (very probably) be written as a < 128 byte ELF binary on
Linux.

------
DannoHung
Going the other way around is probably more interesting...

------
aaronsnoswell
Absolutely fabulous!

------
sneak
I am only an egg.

------
jpinkerton88
mind blown

------
X4
WOAAOOWW!

------
lazyjones
Fake, it's not hard to select colors based on hex values you're reading from a
printouot ... But it does impress some people who think he's actually
designing the code that way.

~~~
edlinfan
> the filling of the pixels with carefully chosen colors

See, to me this means "reading the colors from the printout". It's ridiculous
that anyone could get the least significant bits of the color right by just
eyeballing it, and I don't think the author ever claimed he was doing that.

~~~
lazyjones
> It's ridiculous that anyone could get the least significant bits of the
> color right by just eyeballing it

If you look at the video carefully, you'll see that the color picker displays
numeric RGB values and that it has been sped up. Do you think the code would
work if he didn't get the values 100% right?

~~~
aidos
Of course that values have to be right. The colours are picked to build the
algorithm.

Off to the right side of the screen (not visible) is probably another image
with the colours in that he's picking from.

Maybe it's fake but it's theoretically possible. I don't have a windows pc to
try on. He's provided the image though so you could try for yourself.

