generic animation implementation
This commit is contained in:
parent
7bb1a2ef2d
commit
0bccf22202
1 changed files with 28 additions and 9 deletions
37
viz/viz.py
37
viz/viz.py
|
@ -2,9 +2,31 @@ import numpy as np
|
||||||
import math
|
import math
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import matplotlib.animation as animation
|
import matplotlib.animation as animation
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = plt.subplot(111)
|
||||||
|
ax.set_ylim([0, 5]) # set the bounds to be 10, 10
|
||||||
|
ax.set_xlim([0, 5])
|
||||||
|
|
||||||
def plot_line(angle: float, length: int):
|
class RegrMagic(object):
|
||||||
|
"""Mock for function Regr_magic()
|
||||||
|
"""
|
||||||
|
def __init__(self):
|
||||||
|
self.x = 0.0
|
||||||
|
|
||||||
|
def __call__(self) -> float:
|
||||||
|
self.x += random.randint(-1, 1)
|
||||||
|
return self.x
|
||||||
|
|
||||||
|
regr_magic = RegrMagic()
|
||||||
|
|
||||||
|
def frames():
|
||||||
|
while True:
|
||||||
|
yield regr_magic()
|
||||||
|
|
||||||
|
def plot_line(angle: float):
|
||||||
'''
|
'''
|
||||||
angle - Angle you want your end point at in degrees.
|
angle - Angle you want your end point at in degrees.
|
||||||
length - Length of the line you want to plot.
|
length - Length of the line you want to plot.
|
||||||
|
@ -14,6 +36,7 @@ def plot_line(angle: float, length: int):
|
||||||
|
|
||||||
# unpack the first point
|
# unpack the first point
|
||||||
x, y = (2.5, 2.5)
|
x, y = (2.5, 2.5)
|
||||||
|
length = 20.0
|
||||||
|
|
||||||
# find the end point
|
# find the end point
|
||||||
endx = x + length * math.cos(math.radians(angle))
|
endx = x + length * math.cos(math.radians(angle))
|
||||||
|
@ -22,14 +45,10 @@ def plot_line(angle: float, length: int):
|
||||||
# find the start point
|
# find the start point
|
||||||
startx = x - length * math.cos(math.radians(angle))
|
startx = x - length * math.cos(math.radians(angle))
|
||||||
starty = y - length * math.sin(math.radians(angle))
|
starty = y - length * math.sin(math.radians(angle))
|
||||||
|
ax.clear()
|
||||||
fig = plt.figure()
|
|
||||||
ax = plt.subplot(111)
|
|
||||||
ax.set_ylim([0, 5]) # set the bounds to be 10, 10
|
|
||||||
ax.set_xlim([0, 5])
|
|
||||||
|
|
||||||
# plot the points
|
# plot the points
|
||||||
ax.plot([startx, endx], [starty, endy])
|
return ax.plot([startx, endx], [starty, endy])
|
||||||
plt.show()
|
|
||||||
|
|
||||||
plot_line(-0.9, 20)
|
ani = animation.FuncAnimation(fig, plot_line, frames=frames, interval=10)
|
||||||
|
plt.show()
|
||||||
|
|
Loading…
Reference in a new issue