Animation timing depends on walking speed
This commit is contained in:
parent
950a9447d0
commit
1945cce0e6
2 changed files with 28 additions and 8 deletions
36
moonwalk.py
36
moonwalk.py
|
@ -26,7 +26,7 @@ Interval = float # seconds
|
|||
|
||||
logger = logging.getLogger('moonwalk')
|
||||
|
||||
colorset = [(0, 0, 0),
|
||||
colorset = [(255, 0, 0),
|
||||
(0, 0, 255),
|
||||
(0, 255, 0),
|
||||
(0, 255, 255),
|
||||
|
@ -36,15 +36,15 @@ colorset = [(0, 0, 0),
|
|||
]
|
||||
|
||||
|
||||
walk_image = pyglet.image.load('walk.jpg') # TODO investigaet pyglet.resource: https://pyglet.readthedocs.io/en/latest/programming_guide/image.html#displaying-images
|
||||
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=.2)
|
||||
walk_animation = image_grid.get_animation(period=.05)
|
||||
walk_animation_dim = {
|
||||
'y': walk_animation.get_max_height(),
|
||||
'x': walk_animation.get_max_width()
|
||||
}
|
||||
sprite = pyglet.sprite.Sprite(img=walk_animation)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -54,7 +54,7 @@ class Params:
|
|||
tracker_fps: float = 5.6
|
||||
# iou = None
|
||||
emitter_speed: float = 4 # objects per second
|
||||
object_velocity: float = 80 # pixels/second
|
||||
object_velocity: float = 400 # pixels/second
|
||||
velocity_decay: float = 1 # make system a bit springy
|
||||
iou_threshold: float = 0 # SORT Intersection over union
|
||||
|
||||
|
@ -91,15 +91,17 @@ class Params:
|
|||
for listener in self._listeners[attr]:
|
||||
listener(attr, old_val, val)
|
||||
|
||||
|
||||
|
||||
|
||||
class DetectedObject:
|
||||
def __init__(self, canvas: Canvas):
|
||||
self.canvas = canvas
|
||||
# TODO handle variability
|
||||
self.v = self.canvas.params.object_velocity
|
||||
self.l = 0 # left
|
||||
self.w = 10 # width
|
||||
self.h = 20 # height
|
||||
self.w = 80 # width
|
||||
self.h = 160 # height
|
||||
self.l = -self.w # left
|
||||
self.t = (self.canvas.height - self.h)/2 # top
|
||||
|
||||
# self.shape = pyglet.shapes.Rectangle(self.l, self.t, self.w, self.h, color=(255, 22, 20), batch=self.canvas.batch_figures)
|
||||
|
@ -211,6 +213,9 @@ class Canvas:
|
|||
self.interval_items: list[pyglet.clock._ScheduledIntervalItem] = [i for i in pyglet.clock._default._schedule_interval_items if i.func == self.on_track]
|
||||
self.params.add_listener('tracker_fps', self.on_tracker_fps_change)
|
||||
self.params.add_listener('iou_threshold', self.on_iou_threshold_change)
|
||||
self.params.add_listener('object_velocity', self.on_object_velocity_change)
|
||||
# trigger first time around
|
||||
self.on_object_velocity_change('object_velocity', None, self.params.object_velocity)
|
||||
|
||||
def getTrackBboxShapes(self, track_id):
|
||||
color = colorset[int(track_id) % len(colorset)]
|
||||
|
@ -220,6 +225,7 @@ class Canvas:
|
|||
# pyglet.shapes.Lab(0,0,0,0,color=(0,255,0),thickness=2, batch=self.batch_bounding_boxes)
|
||||
]
|
||||
|
||||
|
||||
def on_tracker_fps_change(self, field, old_value, new_value):
|
||||
"""
|
||||
Param dataclass listener for changes to tracker_fps
|
||||
|
@ -228,6 +234,20 @@ class Canvas:
|
|||
ii.interval = 1/new_value
|
||||
logger.debug(f"Set tracker interval to {ii.interval}")
|
||||
|
||||
def on_object_velocity_change(self, field, old_value, new_value):
|
||||
"""
|
||||
Param dataclass listener for changes to object_velocity as to change walk animation
|
||||
"""
|
||||
duration = max(.001, VELOCITY_FACTOR / new_value)
|
||||
logger.debug(f"set frame duration to {duration=} (for {new_value} p/s, factor: {VELOCITY_FACTOR})")
|
||||
for frame in walk_animation.frames:
|
||||
# a velocity of
|
||||
frame.duration = duration
|
||||
|
||||
# for ii in self.interval_items:
|
||||
# ii.interval = 1/new_value
|
||||
# logger.debug(f"Set tracker interval to {ii.interval}")
|
||||
|
||||
def on_iou_threshold_change(self, field, old_value, new_value):
|
||||
"""
|
||||
Param dataclass listener for changes to iou_threshold
|
||||
|
|
BIN
walk_bw.jpg
Normal file
BIN
walk_bw.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
Loading…
Reference in a new issue