day 9, animation with checked pattern background and colors

This commit is contained in:
setop 2022-12-10 22:51:25 +01:00
parent c8b2258994
commit 9f935aedf7
1 changed files with 12 additions and 7 deletions

View File

@ -5,18 +5,23 @@ import time
class display: class display:
def __init__(self): def __init__(self):
self.w, self.h = tuple(os.get_terminal_size()) self.w, self.h = tuple(os.get_terminal_size())
#self.h -= 1
border = "o" border = "o"
self.delta = numpy.array((self.w//2, self.h//2)) self.delta = numpy.array((self.w//2, self.h//2))
top = border * (self.w) top = border * (self.w)
line = border + " " * (self.w - 2) + border wodd = self.w%2
self.background = top + "".join( lines = [
line for _ in range(self.h - 2)) + top 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): def __call__(self, knots):
print("\033[0;0H", end='') print("\033[0;0H", end='')
x, y = self.delta + knots[0] x, y = self.delta + knots[0]
J = 20 J = 19 # must be odd to see scroll
if x <= 0: if x <= 0:
self.delta[0] += J self.delta[0] += J
if x >= self.w-1: if x >= self.w-1:
@ -25,10 +30,10 @@ class display:
self.delta[1] += J self.delta[1] += J
if y >= self.h-1: if y >= self.h-1:
self.delta[1] -= J 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)): for i,knot in enumerate(reversed(knots)):
x, y = knot + self.delta 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='') print("".join(txt),end='')
time.sleep(.008) time.sleep(.008)