Last active
August 4, 2021 03:51
-
-
Save m-bartlett/0fabbf638dd0c111a77e14d5046ad67c to your computer and use it in GitHub Desktop.
braille animation from binary arrays using numpy
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 numpy as np | |
FRAME_WIDTH = 2 | |
brailles = np.uint8( | |
[ | |
[1,1], [1,0], [1,1], [1,1], [1,1], [1,1], [1,1], [1,1], [0,1], [1,1], [0,1], [1,1], [0,0], [1,1], [0,0], [1,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,1], [0,0], [1,1], [0,0], [1,1], [1,0], | |
[1,0], [0,0], [1,0], [0,0], [0,0], [0,0], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], | |
[0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,1], [0,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], [1,0], [0,0], | |
[0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,0], [0,1], [0,0], [0,1], [0,0], [1,1], [0,0], [1,1], [0,1], [1,1], [0,1], [1,1], [1,1], [1,1], [1,1], [1,1], [1,1], [1,1], [1,1], [1,0], [1,1], [1,0], [1,1], [0,0], [1,1], [0,0], [1,0], [0,0], [1,0], [0,0], [0,0], [0,0], [0,0], [0,0], | |
] | |
) | |
braille_index_np = np.flip(np.uint8([0,1,2,6,3,4,5,7]).argsort()) | |
new_size = (8,np.size(brailles)>>3) | |
brailles=brailles.T.reshape(new_size).T | |
code_points = np.packbits( brailles[:,braille_index_np] ) + 0x2800 | |
frames = list(map(chr, code_points)) | |
print( ''.join(frames) ) | |
import sys | |
from time import sleep | |
for i in range(10): | |
for j in range(0, len(frames), FRAME_WIDTH): | |
print(f"\033[0D\r {''.join(frames[j:j+FRAME_WIDTH])} ", end="") | |
sys.stdout.flush() | |
sleep(0.05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment