This repository has been archived on 2022-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
texty/lib/ascii.py

35 lines
1.3 KiB
Python
Raw Permalink Normal View History

2022-01-25 17:16:07 +01:00
from tempfile import TemporaryDirectory
from time import sleep
2022-01-25 17:16:07 +01:00
from zipfile import ZipFile
from os import listdir, system
2022-01-26 16:07:31 +01:00
import yaml
2022-01-26 09:23:30 +01:00
class AsciiAnimation:
def __init__(self) -> None:
self.frames = []
self.speed = 0.2
2022-01-25 17:16:07 +01:00
2022-01-26 09:23:30 +01:00
def load_ascii(self,name:str):
"""
Loads art from .asc file
2022-01-26 09:23:30 +01:00
"""
2022-05-04 14:26:32 +02:00
with TemporaryDirectory() as tmpdir: # Vytvoříme dočasnou složku
with ZipFile(f"./assets/{name}.asc","r") as z: # Extrahujeme asc soubor
2022-01-26 09:23:30 +01:00
z.extractall(f"{tmpdir}/ascii/{name}")
2022-05-04 14:26:32 +02:00
for f in listdir(f"{tmpdir}/ascii/{name}"): # Přečte soubory
2022-01-26 16:07:31 +01:00
if f == "config.yml":
with open(f"{tmpdir}/ascii/{name}/{f}",encoding="utf-8") as c:
data = yaml.load(c,Loader=yaml.SafeLoader)
if(data["speed"] != None):
self.speed = data["speed"]
2022-05-04 14:26:32 +02:00
with open(f"{tmpdir}/ascii/{name}/{f}",encoding="utf-8") as f: # Přidá všechny snímky do seznamu
self.frames.append(f.read())
def play(self):
"""
Plays the animation frame by frame
"""
for frame in self.frames:
system("cls||clear")
print(frame)
sleep(self.speed)