Created
March 20, 2024 12:29
-
-
Save jquast/2078e138f2cc6f645e774735995f24c7 to your computer and use it in GitHub Desktop.
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
#### note: I wouldn't recommend using the python library of libchafa, at least, at the time of authoriship, | |
### it segfaulted every ~100 calls. I would suggest to use subprocess.Popen family of calls to the 'chafa' | |
### CLI utility, instead. | |
# TODO: calibration of FONT_RATIO: | |
import os | |
# ".. make a perfect circle ..." | |
import blessed | |
from chafa import * | |
from chafa.loader import Loader | |
# The font ratio of JetBrains Mono (width/height) | |
# measured from a widescreen desktop | |
FONT_RATIO = 119/425 | |
# Create a canvas config | |
config = CanvasConfig() | |
import glob | |
files = sorted(glob.glob('fire/*.jpg')) | |
for width in range(10, 400, 10): | |
# Configure the canvas geometry | |
config.width = width | |
config.height = width * FONT_RATIO | |
canvas = Canvas(config) | |
print((config.width, config.height)) | |
# Load the snake | |
config.calc_canvas_geometry(1712, 1310, FONT_RATIO) | |
os.makedirs(f'fire/{width}', exist_ok=True) | |
for n, filename in enumerate(files): | |
fname=f'fire/{width}/frame-{n:04x}.ans' | |
if not os.path.exists(fname): | |
image = Loader(filename) | |
print(image, fname) | |
# Draw to the canvs | |
canvas.draw_all_pixels( | |
image.pixel_type, image.get_pixels(), | |
1712, 1310, 6848) | |
open(fname, 'w').write(canvas.print().decode()) | |
for tmpfile in glob.glob('/tmp/magick-*'): | |
print('-', tmpfile) | |
os.unlink(tmpfile) | |
t = blessed.Terminal() | |
import time | |
with t.hidden_cursor(): | |
while True: | |
for o in outputs: | |
print(t.home, end='', flush=False) | |
time.sleep(0.1) | |
print(o, end='', flush=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment