From 112cbd83da04ed73ed9ef7f2512a282e198496f2 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Tue, 15 Oct 2024 15:33:36 +0200 Subject: [PATCH] Rendered walking animation --- .gitattributes | 2 ++ moonwalk.py | 37 ++++++++++++++++++++----------- walk-animation/walking-body.blend | 3 +++ 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 .gitattributes create mode 100644 walk-animation/walking-body.blend diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..11f949d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.png filter=lfs diff=lfs merge=lfs -text +*.blend filter=lfs diff=lfs merge=lfs -text diff --git a/moonwalk.py b/moonwalk.py index 29d3a30..1841449 100644 --- a/moonwalk.py +++ b/moonwalk.py @@ -36,11 +36,21 @@ colorset = [(255, 0, 0), ] -VELOCITY_FACTOR = 1000*.05 # a pixels/second velocity of 400 gives a frame-duration of .05 -walk_image = pyglet.image.load('walk_bw.jpg') # TODO investigaet pyglet.resource: https://pyglet.readthedocs.io/en/latest/programming_guide/image.html#displaying-images -image_grid = pyglet.image.ImageGrid(walk_image, rows=1, columns=4) -# texture_grid = image_grid.get_texture_sequence() -walk_animation = image_grid.get_animation(period=.05) +VELOCITY_FACTOR = 20*.05 # a pixels/second velocity of 400 gives a frame-duration of .05 + +images_nrs = range(125, 162) +walk_images = [] +for nr in images_nrs: + fn = f'walk-animation/OUT/{nr:03d}_frame{nr}.png' + pic: pyglet.image.ImageData = pyglet.image.load(fn) + walk_images.append(pic) +walk_animation = pyglet.image.animation.Animation.from_image_sequence(walk_images, 2, True) + + +# walk_image = pyglet.image.load('walk_bw.jpg') # TODO investigaet pyglet.resource: https://pyglet.readthedocs.io/en/latest/programming_guide/image.html#displaying-images +# image_grid = pyglet.image.ImageGrid(walk_image, rows=1, columns=4) +# # texture_grid = image_grid.get_texture_sequence() +# walk_animation = image_grid.get_animation(period=.05) walk_animation_dim = { 'y': walk_animation.get_max_height(), 'x': walk_animation.get_max_width() @@ -53,8 +63,8 @@ class Params: # video_fps: float = 60 tracker_fps: float = 5.6 # iou = None - emitter_speed: float = 4 # objects per second - object_velocity: float = 400 # pixels/second + emitter_speed: float = 2 # objects per second + object_velocity: float = 200 # pixels/second velocity_decay: float = 1 # make system a bit springy iou_threshold: float = 0 # SORT Intersection over union @@ -99,8 +109,8 @@ class DetectedObject: self.canvas = canvas # TODO handle variability self.v = self.canvas.params.object_velocity - self.w = 80 # width - self.h = 160 # height + self.w = 160 # width + self.h = 320 # height self.l = -self.w # left self.t = (self.canvas.height - self.h)/2 # top @@ -159,8 +169,8 @@ class Canvas: A canvas with moving objects """ def __init__(self, params: Params): - self.width = 1280 - self.height = 720 + self.width = 1920 + self.height = 1080 self.objects: list[DetectedObject] = [] self.lastSnapshot: Optional[float] = None self.params = params @@ -182,7 +192,7 @@ class Canvas: # self.window.set_handler('on_close', self.on_close) # Purple background color: - # pyglet.gl.glClearColor(*AnimConfig.clear_color) + pyglet.gl.glClearColor(230/255,230/255,230/255,230/255) self.draw_stats = True self.fps_display = pyglet.window.FPSDisplay(window=self.window, color=(255,255,255,255)) self.fps_display.label.x = self.window.width - 150 @@ -349,7 +359,8 @@ class Canvas: for i, object in enumerate(self.objects.copy()): if object.l > self.width: logging.info(f'Delete {i}') - self.objects.pop(i) + el = self.objects.pop(i) + el.shape.delete() # clear the attached shape def snapshot(self) -> list[DetectedObject]: diff --git a/walk-animation/walking-body.blend b/walk-animation/walking-body.blend new file mode 100644 index 0000000..5ba8d5c --- /dev/null +++ b/walk-animation/walking-body.blend @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91eacad30840358d7f38015529edb0c4d2f07bf8ac57bee6e95ef4e744855741 +size 70646980