day 9, animation with checked pattern background and colors
This commit is contained in:
parent
c8b2258994
commit
9f935aedf7
|
@ -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)
|
||||
|
Loading…
Reference in New Issue