Super slow-mo Tetris
04 Feb 2024
A new gadget entered my life a while ago: Father Christmas brought me a Badger 2040W. It’s a wifi-connected computer, that runs python and has an e-ink display. It has fairly low power consumption, and is easily programmed to sleep most of the time. Also e-ink retains an image even when power is removed, so it ought to be able to show something that updates fairly slowly, and run on battery power for many days.
Devices like this are often used to show weather forecasts, train arrivals, latest news, that kind of thing - but they obviously invite customisation and so I was looking for something unique to try out. I asked my friendly team at work for ideas, and a few came up: home dashboard; countdown timer (I love countdowns); personalised news headlines. But the one that piqued my interest was “Tetris”.
e-ink is a bad fit for a game like Tetris, because it has a very slow refresh rate. The one I’ve got takes about 1 sec to do a really clean, sharp update. But the idea began to develop: what if Tetris was slowed down… right down? If you could only make one move per hour, say, and the bricks dropped one brick’s length each hour, then the display could be on the fridge and people in the kitchen could play as a family, debating what to do with “today’s” brick as it dropped.
A fun technical challenge, and likely to throw up some unexpected observations on the way - sounds right up my street. So I wrote some code to get it going.
First up: games like Tetris usually run as a single process, holding the game state in memory. While it is possible to keep a process running for a long time, that’s bad for battery life, so I’ll need some sort of “save game”. Also, I don’t want to lose the game if the battery runs out (take that, handheld gaming!).
Next: deploying code to the device is a bit fiddly, especially when it’s on the fridge. I mean it’s awesome considering everything: I just plug it in with a USB cable. But since it’s going to be internet-connected, I worked towards a set up that lets me just write code, test it locally - even playing it at normal speed - and then just use the device as a sort of specialised display. Its buttons can still send the moves to the cloud, but we can also continue to play remotely, keeping our ever-lasting game alive wherever we are in the world.
I took this working implementation of Tetris and teased out the pygame
dependency, replacing the drawing with Pillow. Instead of inventing a serialisation format to achieve “save game”, I just used pickle
. Now I can run the game in two different ways: live, at normal speed on a normal computer; and static, with the game state stored in a file and visible as a JPG file.
I’ve deployed my code to the cloud and pointed the e-ink computer at it, and yey - we have super slow Tetris running on the fridge. We’ve played a few games. We end up having small debates about what to do with the next piece, and “who let that happen?” when the bricks pile up through inattention.
< Previous post | Next post >Favourite posts
- On wiggly lines and being normal
- On infinite villages
- Running a race backwards
- Brainmaking
- Their tables were stored full, to glad the sight
- The structure of a smell
Recent posts
- Souvenirs des villes européennes
- Pic'n'mix reinvented
- Super slow-mo Tetris
- Skill swaps
- Times Table Hack Stars
Blog archives
Posts from 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024.