Created
July 25, 2022 01:47
-
-
Save ryancdotorg/5f2d5fe7051dfd6e1b2142b0e720609b to your computer and use it in GitHub Desktop.
This file contains 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 sys | |
from PIL import Image | |
from ansifmt import * | |
ansi = AnsiFmt('24bit') | |
#ansi.naive = True | |
uc = '\u2580' | |
lc = '\u2584' | |
def move_cursor(r, c): | |
r += 1 | |
c += 1 | |
sys.stdout.write(f'\033[{r};{c}H') | |
im = Image.open('/home/ryanc/Downloads/avism2.png') | |
px = im.load() | |
pos_col, pos_row = 0, 0 | |
move_cursor(pos_row, pos_col) | |
sys.stdout.write('\033[0J') | |
for r in range(0, 47, 2): | |
grid_row = int(r/2) | |
for c in range(0, 47): | |
grid_col = int(c) | |
ur, ug, ub, ua = px[c, r+0] | |
lr, lg, lb, la = px[c, r+1] | |
if ua == 0 and la == 0: | |
# do nothing | |
pass | |
elif ua > 0 and la > 0: | |
if pos_col != grid_col or pos_row != grid_row: | |
move_cursor(grid_row, grid_col) | |
pos_row, pos_col = grid_row, grid_col | |
sys.stdout.write(ansi.formatter(fg=RGB(ur,ug,ub), bg=RGB(lr,lg,lb))(uc)) | |
#sys.stdout.write('*') | |
pos_col += 1 | |
elif ua == 0 and la > 0: | |
if pos_col != grid_col or pos_row != grid_row: | |
move_cursor(grid_row, grid_col) | |
pos_row, pos_col = grid_row, grid_col | |
sys.stdout.write(ansi.formatter(fg=RGB(lr,lg,lb))(lc)) | |
#sys.stdout.write('*') | |
pos_col += 1 | |
elif ua > 0 and la == 0: | |
if pos_col != grid_col or pos_row != grid_row: | |
move_cursor(grid_row, grid_col) | |
pos_row, pos_col = grid_row, grid_col | |
sys.stdout.write(ansi.formatter(fg=RGB(ur,ug,ub))(uc)) | |
#sys.stdout.write('*') | |
pos_col += 1 | |
move_cursor(24, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment