Skip to content

Commit b28fc4d

Browse files
committed
Fancy output for day 11
1 parent a3f8107 commit b28fc4d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

day_11/__main__.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from typing import Generator, TextIO, List, Dict, Tuple, Set
1+
from typing import Generator, TextIO, Dict
22
import sys
3-
from collections import namedtuple, defaultdict
4-
import functools
5-
import operator
3+
from collections import namedtuple
4+
import time
65

76
Point = namedtuple("Point", ['x', 'y'])
87

8+
COLORS = [(237, 245, 255), (208, 226, 255), (166, 200, 255), (120, 169, 255), (69, 137, 255), (15, 98, 254), (0, 67, 206), (0, 45, 156), (0, 29, 108), (0, 17, 65)]
9+
910
class Cavern:
1011
@staticmethod
1112
def read_input(textio: TextIO) -> "Cavern":
@@ -60,11 +61,14 @@ def __str__(self):
6061
for x in range(self.size.x):
6162
location = Point(x=x, y=y)
6263
energy = self.octopi[location]
63-
if energy == 0:
64-
output += '\033[1m'
65-
output += str(self.octopi[location])
66-
if energy == 0:
67-
output += '\033[0m'
64+
output += '\033['
65+
# if energy == 0:
66+
# output += '1;'
67+
color = COLORS[energy]
68+
output += f'38;2;{color[0]};{color[1]};{color[2]}m'
69+
# output += str(self.octopi[location])
70+
output += u"\u2588"
71+
output += '\033[0m'
6872
output += '\n'
6973
return output
7074

@@ -76,7 +80,9 @@ def _points(self) -> Generator[Point, None, None]:
7680
cavern = Cavern.read_input(sys.stdin)
7781
step = 0
7882
while True:
83+
time.sleep(2/60)
7984
sync = cavern.step()
85+
print('\033[H')
8086
print(cavern)
8187
step += 1
8288
if sync:

0 commit comments

Comments
 (0)