Hacker News new | past | comments | ask | show | jobs | submit login
Snake in a QR Code (itsmattkc.com)
318 points by phit_ on Sept 4, 2020 | hide | past | favorite | 82 comments



If you want to see a variation of this concept in the wild, in active use by lots of people, check out PICO-8 cartidges.

PICO-8 is a virtual game console. I.e. it's an emulator for an oldschool game console that doesn't exist in reality. It's designed to be easy to code for while maintaining the limits and aesthetics of old game computers

PICO-8 games are, of course, distributed on cartridges. However because it's a virtual console, the cartridges are virtual too: they're PNG files.

Try browsing PICO-8 games here: https://www.lexaloffle.com/bbs/?sub=2&cat=7

Press the play button the play a game right inside the web browser, but be sure to click the little "Cart" link right below the playing area to see what's going on. You'll see it open a little PNG file.

That PNG file is the cartridge. It contains the entire game.

The file format is explained here: https://pico-8.fandom.com/wiki/P8PNGFileFormat. Obviously, because PICO-8 carts are purely digital, the format doesn't need any of the contrast, the error correction features or the orientation markers that QR-codes have. You can't take a picture of a cart with your phone and play it. You need the exact same, byte-for-byte PNG file. But it's still super cool.


This is the coolest thing in ages. The game's code is steganographically embedded in a PNG image containing the screenshot of the game! Wow


Steganography is cooler for sure, but can't PNGs already store arbitrary data in the header? IIRC, the game Spore did that so you can exchange creatures by sending images.


I think the issue with that is that many image hosting sites optimize their images or at the least strip unnecessary data and EXIFs.

So at any point while being copied from person to person, that game data could be lost.


Games for the “Redshift” game console in the Zachtronics game Exapunks work the same way. They copied the idea from PICO-8: https://mobile.twitter.com/zachtronics/status/10277956046744...


This is very cool, and gives me a thought, what if you did it without "cheating"? That is, what if the whole game including its rules were in the picture? Something like Conway's game of Life but less shape-dependent, maybe utilizing the color to generate behaviors.


The closest thing I can think of is Piet: https://www.dangermouse.net/esoteric/piet.html


>Richard Mitton supplies this amazing program which calculates an approximation of pi... literally by dividing a circular area by the radius twice.

>Naturally, a more accurate value can be obtained by using a bigger program.

That's delightful


Nintendo back in 2001 came out with the e-Reader that would plug into a Gameboy Advance and read cards with data printed on them. You'd have to scan a few "stripes" of data, but it there were several NES games that you could run if you had the right cards. The cards held the data for the games, rather than them being already on the cartridge https://en.wikipedia.org/wiki/Nintendo_e-Reader


I was always gutted that thing never came out in Europe. I had tons of Pokémon cards with the stripes and nothing to use them with.


You should turn this comment into a blog post. Your writing is captivating. You made this ecosystem sound a lot cooler than the web pages you linked to.


Thanks! I'm humbled :-)

That said, I think the PICO-8 ecosystem is a lot cooler than I made it sound :-)

EDIT, try watching this demo for example: https://www.youtube.com/watch?v=UR3MXKIefAI It's a demo, not a game, so not interactive and hence youtubeable. Tell me that isn't cool (and remember, it fits in is cartridge png).


I don't know if I'm stupid, but those anyone have an example PICO-8 PNG? I can't find one in either of the two links you sent, nor on the internet. Am i missing something here?


Click "Cart" on the bottom left of the BBS entries.

E.g. on https://www.lexaloffle.com/bbs/?tid=29967

Takes you to https://www.lexaloffle.com/bbs/cposts/4/44467.p8.png


Huh, so the PNG actually looks like a real cartridge? How are they able to do that? Is the data section hidden in a non-visible part of the file, or are they able to somehow encode it in there while still having it look visually like a cartridge?


https://pico-8.fandom.com/wiki/P8PNGFileFormat

The images are RGBA PNGs. So for each display pixel there's a byte for each color channel and the alpha channel. The two least significant bits in each byte are a quarter of a PICO-8 data byte. Those bits are read from a channel byte and concatenated in RGBA order to get a data byte.

Using the LSBs for each channel means the those swizzled bits won't contribute very much to that pixel's color value. At worst it would just look like noise in the image.

Also by putting the data inside the image data of a PNG it won't be stripped off by some optimizer or hosting service.


that 'top-down adventure tutorial' is great. basically teaches you everything. thanks for sharing pico-8.


This was the first thing that came to mind. If PICO-8 ever comes out with a mobile version, having a way to load a game by QR Code or some sort of game image would be cool.


Cool, so all the 1k demos/intros from Assembly (https://archive.assembly.org/2019/1k-intro) could also be distributed via QR code... the 4k intros unfortunately not. Maybe it's time for a new category ;)


Or a QR-code paging system.

(I feel a little evil for even suggesting that)


The most interesting applications I've seen of QR-codes have been the most wildly impractical or useless.

When I still used my Pebble watch, my favorite watch face was just a QR-code of the time. So to tell what time it is, you have to scan your watch with your phone.


I love that idea. I couldn't resist mocking one up in Python:

https://pastebin.com/erFSAUvH


I love that it updates every second. It makes it that much harder to actually use.


“Scan Code 22 and Press Button to Continue.”

(If you want to take a guess at what I'm referencing, spoiler alert — the URL itself contains a clue: https://web.archive.org/web/20160129014847/http://i.emezeta.... )


> https://archive.assembly.org/2019/1k-intro

Had to add a security exception only to receive

    404 Not Found
    nginx/1.18.0
:/


You can find the prod executables on https://files.scene.org/browse/parties/2019/assembly19/1k and the placement list and Youtube captures (many prods require quite a hefty GPU to run so YT is the option if you're on a weaker laptop) via http://www.pouet.net/party.php?which=7&when=2019


Thanks!


Or bigger QR codes.


Could you plausibly make it a URL where the code in the URL is assembled and run using webassembly?


The point is to not rely on a server to host anything though. That the QR contains the data itself, not just a URL pointing to the data. Otherwise it is no different from any other QR code that has a URL in it.


The suggestion, I think, is to put the code in the URL itself, not use the URL as a pointer.

You could probably use a data: URL to avoid needing a server at all, but if not, the server would just provide a launcher and not host the application code.


If the binary data is too big to fit in QR, then URL encoding is only going to require more bytes, and it will not fit either.


I wonder if snake could fit in a data uri, like this:

https://bytex64.net/code/datasnake/


that is amazing


I crossed my eyes and stared for ages, still could not see the snake, I hate these magic eye things


Here's another Snake game that can fit in a QR code, this one written in C#: https://twitter.com/MStrehovsky/status/1214955696556515331

(It doesn't need a .NET runtime; it's fully self-contained and runs on Windows as a native app.)


I wish more QR-scanners supported data URLs. I think it would be very cool to distribute tiny web-apps via QR code.


Sounds like https://developer.apple.com/documentation/app_clips except less proprietary, and smaller…


Yeah, let’s make it even easier for people to run random executables that cannot be vetted, preferably on devices tightly coupled to their identities. What could go wrong?


It's not "another way" it's just existing web technology but skipping the download step.


Smartphones are locked down pretty tightly, so I'm not sure how much could actually go wrong compared to what can go wrong with regular apps anway.


Well regular apps are vetted.


Don't worry. There is no malicious code contained within this QR code!


Yeah I'd much prefer it be a javascript: URL that did all the magic in the browser. Much safer, cross platform, and it would probably work out of the box in existing QR reader apps.


But the snake in a QR code probably works offline


A javascript: URL can work offline. Try this: javascript:document.write("hello world");

Note that if you cut and paste into Chrome it may delete the "javascript:" part and you will have to add that back.


Can a QR code convert to JavaScript like that? i.e. instead of opening a webpage it just executes some JavaScript.


That's what I thought about as soon as I read this. Seems like a great malware installation vector.

Just print out stickers and put them up at restaurants, stores...


For which 99.99999% of users will be using mobile clients to scan the QR code that have no capability of executing the code...


Yes, embedding a Windows app is essentially pointless for mobile users, but there are many other delivery vectors available from QR codes.

There are some interesting approaches listed at https://news.sophos.com/en-us/2019/10/17/beware-the-square-h...


Yet. :D


I've been working on a virtual machine where this wouldn't be a problem: https://esolangs.org/wiki/RarVM#Jumping_processes

(small process snapshot sizes and sandboxing capabilities)

Using the WebAssembly VM would be a good alternative for real applications.


Too bad virtually no one will flash it using a Windows device.


Might be interesting to print this on business cards and distribute at conventions or something like that.


"Please run this binary from my business card". I guess it's easier than leaving USB drives in the parking lot...


You could run it in a VM.


YOU could perhaps, but your average target hasn't much of a clue what a VM is, let alone how to set one up.

And keep in mind, malicious software is going to be challenging, and there are much more clever ways to use QR codes.

E.g., imagine some store that has QR codes on the product aisles to access information on a product via a URL. I make a fake website that spoofs the legit product page, but offers the user a special "Buy online and save 25%" offer, which of course they are very tempted by due to the steep discount.


QR code’s support vCards as well. I use QR code that will pop up and ask you to add me to your contacts.

All the data is stored in the QR code.


Boo, use NFC.


And we're back to punch cards. Full circle =]


If you want to play snake in Excel, you can do that too!

https://aaronfrancis.com/2013/remaking-cellphone-snake-in-mi...


I'm still waiting for someone to make an app that encodes and decodes large data into multiple QR codes that are displayed in a moving sequence.

That would be the best way to transfer files in physical locations.


Apple has something like this for their new iOS device setup. I don’t think it’s to encode larger amounts of data, but for security they have this circle that constantly changes shape (see around 0:50 in this video for a demo: https://youtu.be/iE03ypWD5xs). I don’t know for sure how it works, but my first thought was a constantly changing QR-like code.


Someone asked a very similar question on the apple stack exchange[1]. Apple also filed (at least) two patents on the technology[2][3].

[1]: https://apple.stackexchange.com/questions/301563/what-is-the...

[2]: http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=H...

[3]: http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=H...


This would look similar to images produced by the Danmere Backer, a device which let you back up your files to a VHS tape.


Really cool!

He also made a video about it: https://www.youtube.com/watch?v=ExwqNreocpg


It's a cool idea. Here's another one; a Mira fractal generator in SmallBASIC:

https://smallbasic.github.io/images/screenshots/mira.bas.png


I was looking for the snake in the QR code itself (and found it!) before reading the article


Wait, you found a snake? I am confused. Anyways, I too looked for it at first because I expected the game to be visually embedded in the QR code as well. I was a little disappointed that it was not the case. Imagine a game embedded in the QR code that when you load it, either directly is able to reconstruct the QR visual itself, so like some sort of quine https://en.m.wikipedia.org/wiki/Quine_(computing) but with the visual QR being considered the “source” kind of in this case and the thing bring output. Or weaker but still cool if the game uses the camera to load a QR and then you play on it.


Thinking about it a bit more it could be like the PICO-8 mentioned elsewhere ITT but instead of a PNG the QR fantasy console would work by loading programs from QR and initializing the display with the QR visual itself and then the code from the QR is exectuted and is able to access the “video memory” to read in the starting state and then you can play a game where you consume the QR visuals for example with snake. Probably needs to make the snake colored so that you can tell eatable QR visuals apart from your snake. Other games include Breakout and perhaps Pong. Frogger. Etc etc


Could be a really fun variation on quinesnake: https://github.com/taylorconor/quinesnake


I nearly started looking for it - thinking of the SIRDS images that were popular year ago - until I noticed the position markers. It's almost like we're trained in memes...


The HTML5 version converted to a data URL would be a more accessible demo than a windows executable I think, especially if it supported mobile input.

Unfortunately, scanning large QR codes doesn't seem to work too well in practice :(


a new vector emerges


I was thinking about the same thing! Although the original QR code spec did allow binary payloads[1], smartphones and cameras weren't ubiquitous in mid 90s. But they are now. Transmitting computer virus or malware within the QR code binary payload might just be as easy as pointing your camera lens to the QR code. Since the QR code image is only machine readable not human readable, it would be indistinguishable, neither any digital signature to prevent it from being altered.

[1]: https://en.wikipedia.org/wiki/QR_code#Storage


You mean for viruses? Because that's what I was thinking


Am I the only one who thought this would be a game with the roaming around inside a QR code?


nah, i also thought the same


Initially I was looking at the QR-code and thinking about punchcards, code golf and javascript, but reading that it contains a Windows executable was a surprise.


Am I the only one unwilling to run a non-sandboxed process I found on a tech demo?


especially with the included disclaimer

  ...slightly larger than the executable shown in the video because I decided to add a little more functionality


As the demoscene would say, "your loss". It's unfortunate that security hysteria has put such a damper on creativity.

Besides, that binary is small enough that it would be far easier to analyse than the piles of other software you use every day.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: