12 ms·
Writing code with MS Paint
- ja27 16y agoI thought it would be actual opcodes and run - if you could save to a raw, headerless bitmap from Paint.
- lubos 16y agooh common, I thought it was freaking awesome until you ruined it for me
- ypirate 16y agoReal men use Gimp!
- lordlarm 16y agoCan anyone please contribute to how this works?
- perlgeek 16y agoThe maker of the picture wrote the code first in a text editor, and then for each triple of ASCII characters he found the corresponding RGB value, and set one pixel to it. Since the bitmap is just a header (the mojibake you see at the start of the text file) and then a bunch of data bytes, the data bytes can be read as plain text again.
- jcl 16y agoSome other things to note: He is filling in the image from left-to-right, bottom-to-top. That's the scanline order of the data in BMP files, which means he is entering the code in the order it appears in the file. Also, the image he is filling in is eight pixels wide. This is important because the row data in BMP files must be padded to a multiple of four bytes. Each pixel in a 24-bit image takes three bytes. If he had picked a width that wasn't a multiple of four, he would have had garbage padding bytes in the middle of his code.
- rheide 16y agoI'm guessing the bmp format happens to look like ascii for certain pixels with certain colors. I wonder if this works in reverse. Maybe we can program the Mona Lisa in C.
- JoachimSchipper 16y agoC code is too "random" to produce nice images. You can use the least significant bits to hold some data; Google "steganography" (this is just the most basic).
- JonnieCache 16y ago>C code is too "random" to produce nice images In a world where it is possible to compute a file that contains its own MD5, I wouldn't bet on this. Wish I could find the link, there was some feted programmer who had a friend that bet him such a thing was not possible. He proceeded to write an algorithm that found such a file by brute force. I wouldn't count on the eventual C being pretty though. See also: electronic musicians hiding pictures in their music http://www.bastwood.com/?page_id=10 http://www.bastwood.com/?page_id=10
- JoachimSchipper 16y agoYou're right: sane C code is too "random" to produce nice images. ;-)
- JonnieCache 16y agoOne hacker's insanity is another's pastime. http://www.de.ioccc.org/main.html http://www.de.ioccc.org/main.html
- JoachimSchipper 16y agoYeah, that's what I thought of too. Has it been done yet?
- 16y ago
- piaskal 16y agoIt's pretty smart, but very simple. He just puts character ASCII codes into RGB fields in color picker. In 24 bit bmp format those values are saved directly to the file.
- kbutler 16y agoSimple BMP files consist of a header followed by pixel data. By selecting the colors for individual pixels that correspond to the ASCII characters in the source code, a BMP is created that contains the source code. This seems completely useless, until you realize that early computers were programmed by flipping switches to enter the binary values the operator wanted to set... Then you realize that this is entering human-readable high-level language code that would have to be compiled, and with a header that will fail to compile, so yes, this is completely useless. grin
- s2r2 16y agoI thought it would be for „Piet”... http://www.dangermouse.net/esoteric/piet.html http://www.dangermouse.net/esoteric/piet.html
- d0m 16y agoThe use of .gif instead of a flash movie or also pretty ingenious (and a bit oldschool!).
- Samuel_Michon 16y agoI'd say that using Animated GIF is adhering to web standards, using Flash is old school.
- drzaiusapelord 16y agoHow is this a web standard? There really is no standard for video files and if there was, no one is taking gif seriously. There are proposals and half-assed implementations. Hell, not only do gifs look fucking terrible they're also a huge waste of bandwidth. I'd rather just get served an mp4 file or even an embedded flash object instead of this. The only reason why there are so many gifs in the world is because its easy to find free hosting for them and email. Its still a piss poor format for video. Not to mention, the gif people tried suing everyone once. Not exactly the paragon of open you think it is. Don't let Steve Jobs' rivalry with Adobe make you fall in love with sub-par formats. He's glad you uncritically parrot his thinking, but its really not doing anything for you.
- Samuel_Michon 16y agoA screencast is closer to a slideshow than a video. When only 1-5 frames per second are needed, Animated GIF doesn't use much bandwidth. It works in every browser and on very light CPUs. "the gif people tried suing everyone once" You mean Unisys, 'the LZW people'. CompuServe were 'the gif people', who didn't try to sue anyone. Anyways, the LZW patents expired in 2004, so that's no reason to avoid Animated GIFs now. "Don't let Steve Jobs' rivalry with Adobe make you fall in love with sub-par formats. He's glad you uncritically parrot his thinking, but its really not doing anything for you." Thanks for the ad hominem, but I didn't need Steve Jobs to tell me Flash has problems. As a smartphone user, I had already figured that out on my own. However, Adobe can easily win the argument. All they have to do is make Flash safe and stable, and create a fast and power efficient player for mobile devices. I'm just not going to hold my breath. Having said that, the OP could've used far fewer frames, and instead of Animated GIF he could've used a series of JPEGs animated with JavaScript.
- fish2000 16y agoWhat's nice about this is that the color palette he creates in the course of doing this looks as though it'd work well for a syntax-highlighting theme.
- deleted 16y ago[deleted]
- deleted 16y ago[deleted]
- grigy 16y agoLooks like lots of spaces make the picture grayish.
- jgrahamc 16y agoThat's nothing. On the Sharp MZ-80K (http://en.wikipedia.org/wiki/Sharp_MZ#MZ-80K_group http://en.wikipedia.org/wiki/Sharp_MZ#MZ-80K_group) every byte had a printable character that was accessible from the keyboard (see: http://www.ratedesi.com/i/pic/3wuv_OoCvJ8naM:/Com-Museum-Sharp-Mz-80k-Pictures http://www.ratedesi.com/i/pic/3wuv_OoCvJ8naM:/Com-Museum-Sha...). The screen memory was just a part of the standard memory accessed by the Z80 processor, i.e. the screen memory could be executed. Thus it was possible to write a program using the following steps: 1. Write out the Z80 assembly code 2. Convert to opcodes 3. Look up the opcodes in the character map and type the appropriate character on the screen starting at top left Then you could execute the program by calling screen memory (which was possible from BASIC). Happy days. Similarly this made the inclusion of machine code in BASIC programs possible. I would optimize BASIC programs by including machine code subroutines stored as characters in REM statements. It wasn't hard to find those REM statements in memory (as the program was loaded in a fixed location) and call subroutines in the REM statements to speed things up. IIRC correctly I used the same machine code in REM statement trick on the Research Machines 480Z (http://en.wikipedia.org/wiki/LINK_480Z http://en.wikipedia.org/wiki/LINK_480Z) but this involved non-printing characters and thus it was not possible to LIST the entire program and so I typically stored all the machine code in lines numbers less than 100. Which reminds me. On the 480Z there was an 800kbps network using coax. A friend and I disassembled the BIOS and reverse engineered the API (a software interrupt) used for sending and receiving data which enabled us to send arbitrary packets of code to any machine running our interrupt handler. The receive buffer was only 128 bytes, so we would send the machine code in the packet and the receive handler would execute the packet inside the receive buffer. Amazing how much stuff you can do 128 bytes at a time. We wrote a network management package that used this functionality.
- Xuzz 16y agoMore recently, the JailbreakMe iPhone jailbreak used the screen to store the kernel shellcode, since the framebuffer was in a known memory location in both the kernel and userland. Here's a picture I found of it executing the screen: http://img101.imageshack.us/i/ipts.jpg/ http://img101.imageshack.us/i/ipts.jpg/
- 16y ago
- mrcharles 16y agoSo, I was bored after seeing this last week when I submitted it to HN, and so I whipped up a quick python script to shove code in to a BMP file. I bashed it out quick and didn't bother cleaning it up, but here it is: https://github.com/mrcharles/codemap https://github.com/mrcharles/codemap Output from image.py: http://www.bluh.org/codemap.bmp http://www.bluh.org/codemap.bmp Sadly there's still a bug, I think it has to do with alignment padding, which causes a null byte every 520 characters. When I get bored I'll fix it. I think I'm going to write code though to try and make "pretty" images from source code, though in the end it won't be human readable when you open the file.
- lloeki 16y agoMake the image width a multiple of four? (thanks to this comment http://news.ycombinator.com/item?id=2415202 http://news.ycombinator.com/item?id=2415202)
- mrcharles 16y agoYeah, I know that's the fix, I'm just too lazy to do it. When I belted it out I forgot to think about that and then I didn't notice the nulls until someone pointed them out. Oops.
- ot 16y agoIf C++ supported the backwards comment "\\" meaning "everything before this is a comment" described by Stroustrup in http://www2.research.att.com/~bs/whitespace98.pdf http://www2.research.att.com/~bs/whitespace98.pdf, it could be compilable right out of Paint
- gaius 16y agoHaha brilliant! Why didn't they adopt this? Or is there a C++ compiler that does support it?
- jcl 16y agoThat doesn't strike you as a really bad idea? Quite apart from the maintenance nightmare, consider what happens if you need to include a backslash in a string. Read the paper... It also proposes limiting all identifiers to one character, using Wingdings as variables, and overloading whitespace as an operator. ;)
- gaius 16y agoYou've not used APL then ;-) Nesting comments is always a pain in the arse, and \\ would make it unnecessary.
- ot 16y agoHave you noticed the publication date, in the abstract?
- iM8t 16y agoAnyone knows if there's already a code to convert strings of code to images like this? It might be fun to make a few images like that.
- runjake 16y ago2 options: 1.) Google 2.) Read the two threads that were posted here 20 minutes prior to your comment. (Hint: search for "codemap" in page).
- shii 16y agoThis reminds me of 4chan's Cornelia[1][2] (and previously 4chan.js[3]) scripts from a few years ago. [1]: http://encyclopediadramatica.com/Cornelia http://encyclopediadramatica.com/Cornelia [2]: http://blogs.technet.com/b/mmpc/archive/2010/08/09/painting-by-numbers.aspx http://blogs.technet.com/b/mmpc/archive/2010/08/09/painting-... [3]: http://encyclopediadramatica.com/4chan.js http://encyclopediadramatica.com/4chan.js
- deleted 16y ago[deleted]
- hernan7 16y agoAm I the only one dismayed by how drab the resulting image looks?
- SageRaven 16y agoThis is a pretty cool hack, of sorts. There's a hacker conference (I forget which, I think it's "the" demo scene con -- any remember Unreal from the early 90s?) where one of the events is creating a binary executable that is also a displayable image. Or maybe a playable sound file? Anyway, the same basic idea, and when I stumbled across the submissions, I thought it was a really neat concept.
- PlanetFunk 16y agoTo minimise page size I pack the javascript for my html5 game - Last Man Standing: A Zombie Apocalypse - into a png and load it using canvas and eval. It packs my 51KB minified source into an 18KB image file. Works a charm :)