From 9a3e7622565c8dc10546c0ae5f58ed9aa2fcfb4c Mon Sep 17 00:00:00 2001 From: Emily Hunt Date: Sat, 18 Jan 2025 00:28:15 +0100 Subject: [PATCH] Add a camera class that can react to where the skater is --- src/sk8plotlib/camera.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/sk8plotlib/camera.py diff --git a/src/sk8plotlib/camera.py b/src/sk8plotlib/camera.py new file mode 100644 index 0000000..ff8f5d5 --- /dev/null +++ b/src/sk8plotlib/camera.py @@ -0,0 +1,19 @@ +import numpy as np + + +class Camera: + def __init__(self, fig, ax, skater): + self.fig, self.ax, self.skater = fig, ax, skater + + def move_camera(self): + SCALE = 10 + + x, y, v_x, v_y = self.skater.x, self.skater.y, self.skater.v_x, self.skater.v_y + location, velocity = np.asarray([x, y]), np.asarray([v_x, v_y]) + + location += velocity * 0.05 + + self.ax.set( + xlim=(location[0] - SCALE, location[0] + SCALE), + ylim=(location[1] - SCALE, location[1] + SCALE), + ) -- 2.54.0