6 ms·
Real pixel coding (2011)
- lucb1e 14y agoI'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!
- lazyjones 14y agoFake, 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.
- rrrene 14y agoI'm pretty sure that is not what this is about (showing that one can 'paint' coded animations) but to showcase how powerful algorithms are. Am I wrong?
- edlinfan 14y ago> 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 14y ago> 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 14y agoOf 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.
- ux-app 14y agoYou've missed the point of the article. Of course the author is picking from a predefined palette and placing colors in a memorised pattern. This is a theatrical way to demonstrate the main point of the article, which is 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 The video very clearly demonstrated that using only a 9x9x24bit image you can encode a program that, when executed, will produce many MBs of data. It's the same concept as x (k)Bytes of data producing an infinitely scrolling procedurally generated terrain.
- edlinfan 14y agoA great reminder that code is data, and data code. Now I want to see how all my programs look as bitmapped images... brb.
- shurcooL 14y agoHopefully 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 14y agoHopefully 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 14y agoTrue. 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.
- btbuildem 14y agoBack in the days of A500, you could point the video viewport at any part of the memory -- including currently executing code. Watching lz decompress files was mesmerizing.
- jes5199 14y agoYeah, you're describing Shannon entropy: http://en.wikipedia.org/wiki/Entropy_(information_theory) http://en.wikipedia.org/wiki/Entropy_(information_theory) so that means DRY is "try to maximise entropy" gzipped files should also look like random noise, for the same reasons.
- smosher 14y agohttp://esolangs.org/wiki/Piet http://esolangs.org/wiki/Piet
- ygra 14y agoIt'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 14y agoYou'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.
- DanyO 14y agoYeah, that's the first thing that came to my mind before reading the article. http://en.wikipedia.org/wiki/Piet_(programming_language) http://en.wikipedia.org/wiki/Piet_(programming_language)
- libovness 14y ago"Kill two births with one stone" is the most unfortunate malapropism I've ever seen
- javajosh 14y agoAnd 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 14y agoSure, if attracting anti-abortionists to your website is a good thing...
- hnriot 14y agoDoesn't anyone proof read their blog posts anymore...
- alexkus 14y agoI 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 14y agoSee 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 https://en.wikipedia.org/wiki/EICAR_test_file
- jfim 14y ago0xCD19, which is INT 19h (call the bootstrap loader).
- tehwalrus 14y agofinal 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 14y agoYou 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 14y agoThat sounds better than most of the pop music out there. Amusing demonstration of ... something!
- zxcdw 14y agoDemonstration 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.
- algorias 14y agoOf course, it gets linked in the standard way. A program with an empty main takes up about the same space. The point is that this snippet could be compiled very compactly with the right tools.
- tehwalrus 14y agodude, that is awesome! (although, I will now spend a good few hours working out how on earth you get the 16 bar repeats, with variations, and indeed the kick, from some crazy bitshift magic.)
- arocks 14y agoIt 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 http://en.wikipedia.org/wiki/Demoscene
- Jare 14y agoFor reference, this is one of Iñigo's finest creations: http://www.youtube.com/watch?v=jB0vBmiTr6o http://www.youtube.com/watch?v=jB0vBmiTr6o
- afterwise 14y agoAlso: http://www.cgw.com/Publications/CGW/2012/Volume-35-Issue-4-June-July-2012/The-Royal-Treatment.aspx#.UTXPJOtC9hs http://www.cgw.com/Publications/CGW/2012/Volume-35-Issue-4-J...
- metastew 14y agoThat was an excellent read!
- scoot 14y agoIn 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/function2009.pdf http://www.iquilezles.org/www/material/function2009/function...
- CountHackulus 14y agoiq is very well known in the demoscene. He's one of the greatest and most creative coders that there's ever been.
- smrtinsert 14y agowow what an awesome read. the shadow idea is brilliant, so simple and so effective.
- cthackers 14y agoI'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 14y agoThis 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 14y agoInitially 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 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 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 14y agoThanks 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.
- jgrahamc 14y agoBack when I was coding on the Sharp MZ-80K (http://blog.jgc.org/2009/08/in-which-i-switch-on-30-year-old.html http://blog.jgc.org/2009/08/in-which-i-switch-on-30-year-old...) 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 14y agoA 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 14y agoNice. 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 14y agoI'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.
- 14y ago
- Aardwolf 14y ago"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 14y agoExcept 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 14y agoCouldn'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.
- jasonwatkinspdx 14y agoI find it correct and understandable. That's not arrogance. This is basic CS. Reference Kolmogorov complexity. The measure of information relative to a generative basis is the length of the shortest unique representation of a generative description within that basis.
- mpyne 14y agoThe comment you just replied to was pointing out that you could just as easily find a 32x32 pixel icon with Kolmogorov complexity lower than that of the 3 minute "HD" video. And they did so in a way without having to bring CS theory into what was previously a marvelously straightforward discussion.
- X4 14y agoWOAAOOWW!
- aaronsnoswell 14y agoAbsolutely fabulous!
- 6ren 14y agoWow, 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 http://www.java4k.com
- javajosh 14y agoFinally a reason to have the Java Plugin installed, and now for security reasons it's not. Oh, the humanity!
- asmosoinio 14y agoHis image was 9x9 pixels, not 32x32. So 324 bytes.
- deleted 14y ago[deleted]
- Erwin 14y agoThere's this esoteric programming language: http://www.dangermouse.net/esoteric/piet.html 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 http://www.colorforth.com/cf.htm -- this (seems?) more serious.
- islon 14y agoCongratulations, you just gave syntax highlighting a whole new meaning!
- DannoHung 14y agoGoing the other way around is probably more interesting...
- sneak 14y agoI am only an egg.
- shurcooL 14y ago70% 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 14y agoNo 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.
- jpinkerton88 14y agomind blown
- kaoD 14y agoI 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 http://pouet.net/groups.php?which=697
- 9999 14y agoA 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.
- xhrpost 14y agoPretty 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 14y agoYou could presumably run it in DOSBox.