Skip to content

Commit

Permalink
bonus 🎄
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-d committed Dec 14, 2024
1 parent f70aa02 commit ab3031d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
3 changes: 3 additions & 0 deletions 2018/day18/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Lumber Area

![animation](lumberarea.gif)
35 changes: 31 additions & 4 deletions 2018/day18/day18.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from copy import deepcopy
from pathlib import Path

verbose = "-v" in sys.argv
if verbose:
if animation := "-a" in sys.argv:
sys.argv.remove("-a")
if verbose := "-v" in sys.argv:
sys.argv.remove("-v")
self_tests = "-T" in sys.argv
if self_tests:
if self_tests := "-T" in sys.argv:
sys.argv.remove("-T")
filename = ("test.txt" if sys.argv[1] == "-t" else sys.argv[1]) if len(sys.argv) > 1 else "input.txt"
data = Path(filename).read_text().strip()
Expand Down Expand Up @@ -89,6 +89,33 @@ def animate(area):
a = collect(a)


if animation:
import os

from imgcat import imgcat
from PIL import Image

frames = []
a = deepcopy(area)
for i in range(500):

frame = Image.new("RGB", (N * 4, N * 4))
for x in range(N):
for y in range(N):
c = ((0, 0, 0), (0, 255, 0), (165, 42, 42))[a[y * N + x]]
for k in range(16):
frame.putpixel((x * 4 + k // 4, y * 4 + k % 4), c)

frame.save(f"frame{i}.png")
frames.append(f"frame{i}.png")

a = collect(a)

os.system("magick -delay 3 -loop 0 " + " ".join(frames) + " lumberarea.gif")
for f in frames:
os.unlink(f)


if verbose:
animate(area)

Expand Down
Binary file added 2018/day18/lumberarea.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions 2019/day13/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Advent of Code Cabinet 🎮

[![asciicast](https://asciinema.org/a/bBZnFo6tAzRxECjVLY7OQmPOz.svg)](https://asciinema.org/a/bBZnFo6tAzRxECjVLY7OQmPOz)

0 comments on commit ab3031d

Please sign in to comment.