frames.py
774 B · python · 20 lines
1import os2from mrlypy.paint.colors import get_color3from mrlypy.paint.enums import Ink4from .helpers import logger5from .models import Life67BLACK = get_color(Ink.BLACK)8WHITE = get_color(Ink.WHITE)910def create_frames(result: Life, scale=10, output_dir="data/life/frames", format="png", prefix="life") -> str:11 logger.debug(f"Creating {len(result.grids)} frames")12 os.makedirs(output_dir, exist_ok=True)13 for i, grid in enumerate(result.grids):14 grid.paint({0: [BLACK], 1: [WHITE]})15 image = grid.to_image(scale).convert("RGB")16 fp = f"{output_dir}/{prefix}_{i+1:03d}.{format}"17 image.save(fp, format=format)18 logger.debug(f"Saved: {fp}")19 logger.info(f"Saved {len(result.grids)} frames to {output_dir}")20 return output_dir