diff --git a/d09/animp.py b/d09/anim.py similarity index 72% rename from d09/animp.py rename to d09/anim.py index 9f76065..00930e7 100644 --- a/d09/animp.py +++ b/d09/anim.py @@ -5,18 +5,23 @@ import time class display: def __init__(self): self.w, self.h = tuple(os.get_terminal_size()) - #self.h -= 1 border = "o" self.delta = numpy.array((self.w//2, self.h//2)) top = border * (self.w) - line = border + " " * (self.w - 2) + border - self.background = top + "".join( - line for _ in range(self.h - 2)) + top + wodd = self.w%2 + lines = [ + border + "░ " * (self.w//2-1) + "░"*wodd + border, + border + " ░" * (self.w//2-1) + " "*wodd + border + ] + self.background = [ + top + "".join(lines[h%2] for h in range(self.h - 2)) + top, + top + "".join(lines[1-h%2] for h in range(self.h - 2)) + top + ] def __call__(self, knots): print("\033[0;0H", end='') x, y = self.delta + knots[0] - J = 20 + J = 19 # must be odd to see scroll if x <= 0: self.delta[0] += J if x >= self.w-1: @@ -25,10 +30,10 @@ class display: self.delta[1] += J if y >= self.h-1: self.delta[1] -= J - txt = [c for c in self.background] + txt = [c for c in self.background[sum(self.delta)%2]] for i,knot in enumerate(reversed(knots)): x, y = knot + self.delta - txt[int(x + y * self.w)] = str(9-i) + txt[int(x + y * self.w)] = "\033[30;43m" + str(9-i) + "\033[0m" print("".join(txt),end='') time.sleep(.008)