Created
January 31, 2026 20:14
-
-
Save denilsonsa/cd02fe44bf8b8fb9bce879427e44186e to your computer and use it in GitHub Desktop.
Experiment drawing tic-tag-toe on micro:bit 5x5 LED matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Try this at https://python.microbit.org/v/3 | |
| # Problem: how to make two distinct "sprites" for each player of tic-tac-toe, if all we have is just a single pixel? | |
| # Solution: I don't know! | |
| # I've tried making each pixel animate (blink) in different brightness ans patterns. | |
| # I'm still not happy with the result, but I didn't want to throw away this code. | |
| # Maybe I should make them blink alternately (i.e. out-of-phase). | |
| # Maybe I should use the intermediate pixels to "join" cells that are of the same type, similar to how Puyo Puyo graphics work. | |
| from microbit import * | |
| def generate_images(board): | |
| tiles = [ | |
| board[0], '|', board[1], '|', board[2], ':', | |
| '|' , '|', '|' , '|', '|', ':', | |
| board[3], '|', board[4], '|', board[5], ':', | |
| '|' , '|', '|' , '|', '|', ':', | |
| board[6], '|', board[7], '|', board[8], ':', | |
| ] | |
| sprites = { | |
| ' ': '00000000', | |
| # 'X': '91919191', | |
| # 'O': '56787654', | |
| # 'X': '51515151', | |
| 'X': '56565656', | |
| 'O': '98789878', | |
| '|': '33333333', | |
| ':': '::::::::', | |
| } | |
| return [ | |
| Image( | |
| ''.join( | |
| sprites[t][i] for t in tiles | |
| ) | |
| ) for i in range(len(sprites[' '])) | |
| ] | |
| b = ( | |
| 'X O' | |
| ' XO' | |
| 'O X' | |
| ) | |
| while True: | |
| display.show(generate_images(b)*20, delay=1000 // 25, wait=True) | |
| sleep(1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment