diff --git a/display/dislpay_2d.py b/display/dislpay_2d.py index 963cfbe..36b7fa4 100644 --- a/display/dislpay_2d.py +++ b/display/dislpay_2d.py @@ -1,11 +1,6 @@ import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation import numpy as np -import matplotlib.gridspec as gridspec -from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes -import functools -from time import sleep -import itertools # @@ -22,6 +17,29 @@ class Displayer: self._circle_map = {} self._objects = [] + self._xlim = [0, 20] + self._ylim = [0, 20] + + + def __init_animation(self): + self._ax.set_xlim(self._xlim) + self._ax.set_ylim(self._ylim) + + for key in self._circle_map: + self._ax.add_patch(self._circle_map[key]) + + return self._objects + + + # + # Functions for initalization + # + + + def set_axis_limits(self, min, max): + self._xlim = (min, max) + self._ylim = (min, max) + def register_object(self, obj_name, obj_color='r'): self._object_map[obj_name], = plt.plot([], [], color=obj_color, marker='o') @@ -31,19 +49,22 @@ class Displayer: self._objects.append(self._circle_map[obj_name]) + # + # Functions to be used in the animation callback + # + + def move_object(self, obj_name, x, y): self._object_map[obj_name].set_data([x, y]) self._circle_map[obj_name].center = (x, y) + def set_circle_radius(self, obj_name, r): + self._circle_map[obj_name].radius = r - def __init_animation(self): - self._ax.set_xlim(0, 20) - self._ax.set_ylim(0, 20) - for key in self._circle_map: - self._ax.add_patch(self._circle_map[key]) - - return self._objects + # + # Start the animation + # def animate(self, n_steps, anim_callback): diff --git a/examples/gps_fusion.py b/examples/gps_fusion.py index a86adfc..993b2bc 100644 --- a/examples/gps_fusion.py +++ b/examples/gps_fusion.py @@ -8,11 +8,15 @@ from display.dislpay_2d import Displayer def update(disp, t): disp.move_object("test", t, t) - disp.move_object("test2", 20-t, 20-t) + disp.move_object("test2", 20-t, t) + disp.set_circle_radius("test", t*0.2) + def run(): disp = Displayer(width=6, height=6) - #disp.show_object([1, 1], 4, "green") - disp.register_object("test") - disp.register_object("test2", 'g') - disp.animate(n_steps = 100, anim_callback=update) \ No newline at end of file + + disp.set_axis_limits(min=0, max=20) + disp.register_object("test", "red") + disp.register_object("test2", "black") + + disp.animate(n_steps = 20, anim_callback=update) \ No newline at end of file