You can now play ‘Tetris’ in a PDF file


There’s a global community dedicated to finding new ways to challenge themselves in Tetris, from speedruning the classic puzzler to technically “beating” it. But the latest feat isn’t a newly discovered hidden glitch or high score—it’s an entirely new way to play the game.

Thomas Rinsma, a security analyst and hobbyist tinkerer, recently figured out how to create a version of Tetris that runs inside a PDF file. According to a personal website post subsequently highlighted by BoingBoing on January 15th, Rinsma tackled the project “just for fun” after learning the potential implementations of PDF’s JavaScript API. The result is a novel version Rinsma calls PDFTRIS.

PDFTRIS in action. Credit: Popular Science

“[I] realized there just might be enough I/O possibility there for a game,” he wrote. “I/O” stands for “Input/Output,” and refers to the communication between a computer and its users.

Rinsma explained that it’s already “relatively well-known” that PDFs can support a number of features such as dynamic content scripting when opened in something like Adobe Acrobat/Reader. Some of that same scripting support, however, is also available in both Mozilla Firefox and Google Chromium’s respective PDF readers, PDF.js and PDFium.

[ Related: Is Tetris infinite? Teen world champ reaches fabled ‘rebirth’ ]

It gets a bit complex to the layperson from there, but regardless, the end result is a PDF containing a 10×20 grid of field buttons. These alternate between shaded and empty blocks depending on the JavaScript input, allowing a player to use preprogrammed keyboard instructions to move and shift the tetronimoes—the official term for four-block shapes such as those in Tetris blocks.

“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,” Rinsma wrote in a post to Hacker News.

Throw in the ability for the file to automatically loop and reload each command, and you have a functional game of Tetris. It even speeds up as your score increases. Anyone interested in checking under PDFTRIS’s hood can check out Rinsma’s open-source files available on GitHub.

For those in the know, the ability to play a video game in a PDF file begs a certain, extremely specific programming community question. As luck would have it, Rinsma already has the answer: Yes, PDFs can also run Doom.

 

ps ggs

Win the Holidays with PopSci’s Gift Guides

Shopping for, well, anyone? The PopSci team’s holiday gift recommendations mean you’ll never need to buy another last-minute gift card.

 



Source link

About The Author

Scroll to Top