Try to fix snake
All checks were successful
docker-image / docker (push) Successful in 9m49s

This commit is contained in:
Stefan Bethke 2025-06-06 18:40:14 +02:00
commit 4405ccfd66
2 changed files with 9 additions and 4 deletions

View file

@ -34,7 +34,7 @@ animator.add(DBFAnimation, ds100="AHST", station="Holstenstraße")
animator.add(DBFAnimation, ds100="AHS", station="Altona", count=9) animator.add(DBFAnimation, ds100="AHS", station="Altona", count=9)
animator.add(IcalEvents, url="https://cloud.hamburg.ccc.de/remote.php/dav/public-calendars/QJAdExziSnNJEz5g?export", animator.add(IcalEvents, url="https://cloud.hamburg.ccc.de/remote.php/dav/public-calendars/QJAdExziSnNJEz5g?export",
title="CCCHH Events") title="CCCHH Events")
# animator.add(SnakeAnimation) animator.add(SnakeAnimation)
@app.route("/static/<filepath>") @app.route("/static/<filepath>")
def server_static(filepath): def server_static(filepath):

View file

@ -13,6 +13,7 @@ class SnakeAnimation(BubaAnimation):
self.width = 20 self.width = 20
self.height = 4 self.height = 4
self.grid = [] self.grid = []
self.prev_grid = []
self.body = [] self.body = []
# 0:Space # 0:Space
self.charset = " " self.charset = " "
@ -35,6 +36,7 @@ class SnakeAnimation(BubaAnimation):
def run(self): def run(self):
self.grid = [list([0] * self.width) for i in range(self.height)] self.grid = [list([0] * self.width) for i in range(self.height)]
self.prev_grid = [list([0] * self.width) for i in range(self.height)]
x = random.randrange(self.width) x = random.randrange(self.width)
y = random.randrange(self.height) y = random.randrange(self.height)
d = random.randrange(4) d = random.randrange(4)
@ -97,6 +99,9 @@ class SnakeAnimation(BubaAnimation):
self.grid[y][x] != 0) self.grid[y][x] != 0)
def render(self): def render(self):
for r, row in enumerate(self.grid): for x in range(self.width):
for c, col in enumerate(row): for y in range(self.height):
self.buba.text(0, r, c*6, (c+1)*6-1, self.charset[col]) if self.grid[y][x] != self.prev_grid[y][x]:
c = x*6
self.buba.text(0, y, c, c+5, self.charset[self.grid[y][x]])
self.prev_grid[y][x] = self.grid[y][x]