Skip to content

Commit 8c2606b

Browse files
committed
Formatting
1 parent 8f7d4b9 commit 8c2606b

File tree

1 file changed

+30
-15
lines changed
  • challenges/2024/08-resonantCollinearity

1 file changed

+30
-15
lines changed

challenges/2024/08-resonantCollinearity/vis.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ def parse(instr: str) -> tuple[dict[str, list[coord.Coordinate]], tuple[int, int
2929

3030
def get_colour_for(n):
3131
return tuple(
32-
map(int, map(lambda x: x[0] - x[1], zip(lowest_colour, map(lambda x: x * n, colour_diffs))))
32+
map(
33+
int,
34+
map(
35+
lambda x: x[0] - x[1],
36+
zip(lowest_colour, map(lambda x: x * n, colour_diffs)),
37+
),
38+
)
3339
)
3440

41+
3542
scale_factor = 8
3643

3744

@@ -41,23 +48,25 @@ def get_highlight_for(n):
4148

4249
def generate_frame(i, base_img, highlight_locs, hc, sequence) -> int:
4350
for n in range(len(sequence)):
44-
s = sequence[:n+1]
51+
s = sequence[: n + 1]
4552
img = base_img.copy()
46-
53+
4754
sl = len(s) + 1
4855
for j, p in enumerate(s):
4956
img.putpixel(p, get_colour_for((j + 1) / sl))
50-
57+
5158
for h in highlight_locs:
5259
img.putpixel(h, hc)
53-
60+
5461
maxx, maxy = img.size
55-
img = img.resize((maxx * scale_factor, maxy * scale_factor), resample=Image.NEAREST)
62+
img = img.resize(
63+
(maxx * scale_factor, maxy * scale_factor), resample=Image.NEAREST
64+
)
5665
img.save(f"frames/{str(i).zfill(5)}.png")
5766
i += 1
5867
return i
59-
60-
68+
69+
6170
def update_base(base_img, add):
6271
for v in add:
6372
base_img.putpixel(v, shadow_colour)
@@ -66,17 +75,17 @@ def update_base(base_img, add):
6675
if __name__ == "__main__":
6776
inp = sys.stdin.read().strip()
6877
(antenna_by_type, (max_x, max_y)) = parse(inp)
69-
78+
7079
ns = list(sorted(antenna_by_type.keys()))
7180
nns = len(ns)
72-
81+
7382
try:
7483
os.makedirs("frames")
7584
except FileExistsError:
7685
pass
77-
78-
base_img = Image.new("RGB", (max_x+1, max_y+1), color=lowest_colour)
79-
86+
87+
base_img = Image.new("RGB", (max_x + 1, max_y + 1), color=lowest_colour)
88+
8089
i = 0
8190
for antenna_type in tqdm(antenna_by_type):
8291
for (a, b) in itertools.permutations(antenna_by_type[antenna_type], 2):
@@ -101,6 +110,12 @@ def update_base(base_img, add):
101110
this_iter.append((x_cursor, y_cursor))
102111
x_cursor += diff.x
103112
y_cursor += diff.y
104-
105-
i = generate_frame(i, base_img, (a, b), get_highlight_for(ns.index(antenna_type) / nns), this_iter)
113+
114+
i = generate_frame(
115+
i,
116+
base_img,
117+
(a, b),
118+
get_highlight_for(ns.index(antenna_type) / nns),
119+
this_iter,
120+
)
106121
update_base(base_img, this_iter)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy