Formatting
This commit is contained in:
parent
8f7d4b9278
commit
8c2606b60b
1 changed files with 30 additions and 15 deletions
|
@ -29,9 +29,16 @@ colour_diffs = tuple(map(lambda x: x[1] - x[0], zip(highest_colour, lowest_colou
|
||||||
|
|
||||||
def get_colour_for(n):
|
def get_colour_for(n):
|
||||||
return tuple(
|
return tuple(
|
||||||
map(int, map(lambda x: x[0] - x[1], zip(lowest_colour, map(lambda x: x * n, colour_diffs))))
|
map(
|
||||||
|
int,
|
||||||
|
map(
|
||||||
|
lambda x: x[0] - x[1],
|
||||||
|
zip(lowest_colour, map(lambda x: x * n, colour_diffs)),
|
||||||
|
),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
scale_factor = 8
|
scale_factor = 8
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,23 +48,25 @@ def get_highlight_for(n):
|
||||||
|
|
||||||
def generate_frame(i, base_img, highlight_locs, hc, sequence) -> int:
|
def generate_frame(i, base_img, highlight_locs, hc, sequence) -> int:
|
||||||
for n in range(len(sequence)):
|
for n in range(len(sequence)):
|
||||||
s = sequence[:n+1]
|
s = sequence[: n + 1]
|
||||||
img = base_img.copy()
|
img = base_img.copy()
|
||||||
|
|
||||||
sl = len(s) + 1
|
sl = len(s) + 1
|
||||||
for j, p in enumerate(s):
|
for j, p in enumerate(s):
|
||||||
img.putpixel(p, get_colour_for((j + 1) / sl))
|
img.putpixel(p, get_colour_for((j + 1) / sl))
|
||||||
|
|
||||||
for h in highlight_locs:
|
for h in highlight_locs:
|
||||||
img.putpixel(h, hc)
|
img.putpixel(h, hc)
|
||||||
|
|
||||||
maxx, maxy = img.size
|
maxx, maxy = img.size
|
||||||
img = img.resize((maxx * scale_factor, maxy * scale_factor), resample=Image.NEAREST)
|
img = img.resize(
|
||||||
|
(maxx * scale_factor, maxy * scale_factor), resample=Image.NEAREST
|
||||||
|
)
|
||||||
img.save(f"frames/{str(i).zfill(5)}.png")
|
img.save(f"frames/{str(i).zfill(5)}.png")
|
||||||
i += 1
|
i += 1
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
def update_base(base_img, add):
|
def update_base(base_img, add):
|
||||||
for v in add:
|
for v in add:
|
||||||
base_img.putpixel(v, shadow_colour)
|
base_img.putpixel(v, shadow_colour)
|
||||||
|
@ -66,17 +75,17 @@ def update_base(base_img, add):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
inp = sys.stdin.read().strip()
|
inp = sys.stdin.read().strip()
|
||||||
(antenna_by_type, (max_x, max_y)) = parse(inp)
|
(antenna_by_type, (max_x, max_y)) = parse(inp)
|
||||||
|
|
||||||
ns = list(sorted(antenna_by_type.keys()))
|
ns = list(sorted(antenna_by_type.keys()))
|
||||||
nns = len(ns)
|
nns = len(ns)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.makedirs("frames")
|
os.makedirs("frames")
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
base_img = Image.new("RGB", (max_x+1, max_y+1), color=lowest_colour)
|
base_img = Image.new("RGB", (max_x + 1, max_y + 1), color=lowest_colour)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for antenna_type in tqdm(antenna_by_type):
|
for antenna_type in tqdm(antenna_by_type):
|
||||||
for (a, b) in itertools.permutations(antenna_by_type[antenna_type], 2):
|
for (a, b) in itertools.permutations(antenna_by_type[antenna_type], 2):
|
||||||
|
@ -101,6 +110,12 @@ if __name__ == "__main__":
|
||||||
this_iter.append((x_cursor, y_cursor))
|
this_iter.append((x_cursor, y_cursor))
|
||||||
x_cursor += diff.x
|
x_cursor += diff.x
|
||||||
y_cursor += diff.y
|
y_cursor += diff.y
|
||||||
|
|
||||||
i = generate_frame(i, base_img, (a, b), get_highlight_for(ns.index(antenna_type) / nns), this_iter)
|
i = generate_frame(
|
||||||
|
i,
|
||||||
|
base_img,
|
||||||
|
(a, b),
|
||||||
|
get_highlight_for(ns.index(antenna_type) / nns),
|
||||||
|
this_iter,
|
||||||
|
)
|
||||||
update_base(base_img, this_iter)
|
update_base(base_img, this_iter)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue