summaryrefslogtreecommitdiff
path: root/main2.py
blob: 9730ba90fe5a85f32cae8bad204786f0dfedc49c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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')