from PIL import Image from sys import argv def detect_size_from_file(filename: str): x = None y = 0 with open(filename, 'r') as s: lines = s.readlines() for line in lines: line = line.strip() if line == '': return (x, y) y = y + 1 if not x: x = len(line) if x != len(line): raise ValueError("Lines are not equal") return (x,y) def set_pixels(image, frame, lightup="*"): x = 0 y = 0 for line in frame: for bit in line: print(x, y) if bit == lightup: image.putpixel((x, y), 255) x = x + 1 y = y + 1 x = 0 return image def split_frames(filename, frame_separator = ''): with open(filename, 'r') as fh: lines = fh.readlines() if not any([line for line in lines if line.strip() == frame_separator]): raise TypeError("Not an animation") frame = [] for line in lines: if line.strip() != frame_separator: frame.append(line) else: print(frame) yield frame frame = [] if frame: yield frame def create_image(size: list): return Image.new("1", size) if len(argv) == 2: xy = detect_size_from_file(argv[1]) print(xy) image = create_image(xy) try: for idx, frame in enumerate(split_frames(argv[1])): print(frame) image = set_pixels(image, frame) image.save('test_{}.png'.format(idx), "PNG") except TypeError: print("nope")