import json import time import shutil import os import datetime from PIL import Image divider = 10 dates = {} data = json.load(open('data.json')) image = Image.open('initial.png') initial = Image.open('initial.png') image.save('frame.png') total = len(data) def hex_to_rgb(value): value = value.lstrip('#') return int(value[0:2], 16), int(value[2:4], 16), int(value[4:6], 16) """ def hex_to_rgb(value): value = value.lstrip('#') lv = len(value) return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3)) """ colors = [ "#6D001A", "#BE0039", "#FF4500", "#FFA800", "#FFD635", "#FFF8B8", "#00A368", "#00CC78", "#7EED56", "#00756F", "#009EAA", "#00CCC0", "#2450A4", "#3690EA", "#51E9F4", "#493AC1", "#6A5CFF", "#94B3FF", "#811E9F", "#B44AC0", "#E4ABFF", "#DE107F", "#FF3881", "#FF99AA", "#6D482F", "#9C6926", "#FFB470", "#000000", "#515252", "#898D90", "#D4D7D9", "#FFFFFF", "#ffff5c", "#d9d94a", "#ff7313", "#fce07c", "#bdbd3e", "#c0aa19", "#8f8fe0", "#6b6bd1", "#9efe90", "#360082", "#00ccff", "#44b1ce", "#4a2157", "#d676e3", "#abfbff", "#a11461", "#592d1b", "#914724", "#cc6d42", "#ff8559", "#ffd5ad", "#d39748", "#fa74a4", "#ffd1dc", "#679112", "#d39648", "#9fc455", "#d5ebad", "#adafb0", "#793ccf", "#a771f7", "#d3bff5", ] frame = 1 frameFile = 1 times = [] for event in data: percentage = "%.2f" % ((frame / total) * 100) remaining = total - frame if len(times) > 0: avg = sum(times) / len(times) else: avg = 0 eta = None if frame > 1000: eta = avg * remaining if eta is not None: eta_seconds = round(eta / 1000000000) eta_string = str(eta_seconds) + " seconds remaining" done_by = datetime.datetime.fromtimestamp(round(time.time() + eta_seconds)).isoformat().split("T")[1] if eta_seconds > 60: if eta_seconds > 3600: if round(eta_seconds / 3600) > 1: eta_string = str(round(eta_seconds / 3600)) + " hours remaining" else: eta_string = str(round(eta_seconds / 3600)) + " hour remaining" else: if round(eta_seconds / 60) > 1: eta_string = str(round(eta_seconds / 60)) + " minutes remaining" else: eta_string = str(round(eta_seconds / 60)) + " minute remaining" print(f"\r{frame}/{total} ({percentage}% complete, {eta_string}, done at {done_by})", end="", flush=True) else: print(f"\r{frame}/{total} ({percentage}% complete, calculating...)", end="", flush=True) start = time.time_ns() if 'x' in event and 'y' in event: # Normal pixel placement if colors[event['color']] is not None: image.putpixel((event['x'], event['y']), hex_to_rgb(colors[event['color']])) else: # Mod tool if 0 <= event['x1'] <= 1000 and 0 <= event['x2'] <= 1000 \ and 0 <= event['y1'] <= 1000 and 0 <= event['y2'] <= 1000: for x in range(event['x1'], event['x2']): for y in range(event['y1'], event['y2']): if colors[event['color']] is not None: image.putpixel((x, y), hex_to_rgb(colors[event['color']])) frame += 1 end = time.time_ns() duration = end - start times.append(duration) print("\r\nSaving frame to 'frame.png'...") image.save(f'frame.png')