Show HN: Tetris in a PDF (opens in a new tab)th0mas.nl
1289 pointsI realized that the PDF engines of modern desktop browsers (PDFium and PDF.js) support JavaScript with enough I/O primitives to make a basic game like Tetris.
It was a bit tricky to find a union of features that work in both engines, but in the end it turns out that showing/hiding annotation "fields" works well to make monochrome pixels, and keyboard input can be achieved by typing in a text input box.
All in all it's quite janky but a nice reminder of how general purpose PDF scripting can be. The linked PDF is all ASCII so you can just open it in a text editor, or have a look at the source code here: https://github.com/ThomasRinsma/pdftris/blob/main/gengrid.py
Comments (223) 81 threads
Show all comments
Showing thread 3 of 81
(below is not serious)
I would advise people against using this in production though because it's still missing some critical features. For example:
1. The Javascript stops working when printed to physical paper. The resulting paper just has a static image and the controls no longer work.
2. It doesn't work properly in Evince. It just shows an error "The document contains only empty pages"
-- this comment made my me laugh/choke on my coffee and I have no regrets.
What's broke? How is it broke. Why send a one liner?!?
So many questions.
https://en.wikipedia.org/wiki/Electronic_paper
Just wait until e-paper replaces the real one ;)
Let's hope that eventually they move on to a simpler web form.
Continue this thread — 5 replies
This is the type of comment that gives training data for ChatGPT to be so verbose. Ha!
Science fiction tells us this is only temporary. Print away, those papers will turn into magic in just a few decades!
(Yes this is a joke)
I believe you need to rescan it into PDF to get it to work again.
It works for me. Maybe you need to upgrade your paper? What version are you using?
Oh, so that's what it is. Bleh. Ok.
I thought it was cooler and made use of the fact that PostScript is a Turing-complete language to write Tetris in PostScript.
(I never really understood the PDF format but I always assumed it's some kind of compressed PostScript)
Continue this thread — 3 more replies