textgrid-rust/demo.py
2026-07-20 12:53:51 +10:00

41 lines
1 KiB
Python

"""Animated Unicode pattern using the GPU-accelerated text grid extension."""
import math
import textgrid
import time
ROWS = 24
COLS = 80
FONT_PATH = None # set to a .ttf path to override DejaVu Sans Mono
# Unicode gradient blocks from light to dark
BLOCKS = " ░▒▓█"
def main():
tg = textgrid.TextGrid(ROWS, COLS, font_path=FONT_PATH)
time.sleep(0.3)
t0 = time.monotonic()
frame = 0
duration = 10
while time.monotonic() - t0 < duration:
rows = []
for y in range(ROWS):
row_chars = []
phase = frame * 0.08 + y * 0.4
for x in range(COLS):
dx = x - COLS / 2
dy = y - ROWS / 2
v = math.sin(math.sqrt(dx * dx + dy * dy) * 0.25 - phase)
v = max(-1, min(1, v))
idx = int((v + 1) * 0.5 * (len(BLOCKS) - 1))
row_chars.append(BLOCKS[idx])
rows.append("".join(row_chars))
tg.update(rows)
frame += 1
print(frame)
tg.close()
if __name__ == "__main__":
main()