Inspired by the animation when using gh run download
Created
October 6, 2025 00:21
-
-
Save HactarCE/d22871987c0db470687c2c0d64278394 to your computer and use it in GitHub Desktop.
Terminal loading animation using Braille patterns
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
| #!/usr/bin/env python3 | |
| import time | |
| DELAY = 1/20 | |
| dot_order = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (0, 3), (1, 3)] | |
| coordinates = set() | |
| def toggle(pos): | |
| if pos in coordinates: | |
| coordinates.remove(pos) | |
| else: | |
| coordinates.add(pos) | |
| def br(x0, y0): | |
| bits = sum(((x0+x, y0+y) in coordinates) << i for (i, (x, y)) in enumerate(dot_order)) | |
| return chr(0x2800 + bits) | |
| def update(): | |
| print(f'\r{br(0, 0)}{br(2, 0)} ', end='') | |
| loop = [(2, 0), (3, 0), (3, 1), (3, 2), (3, 3), (2, 3), (1, 3), (0, 3), (0, 2), (0, 1), (0, 0), (1, 0)] | |
| length = 6 | |
| for pos in loop[:length]: | |
| toggle(pos) | |
| try: | |
| while True: | |
| for i in range(len(loop)): | |
| toggle(loop[i % len(loop)]) | |
| toggle(loop[(i+length) % len(loop)]) | |
| update() | |
| time.sleep(DELAY) | |
| except KeyboardInterrupt: | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment