initial animation

This commit is contained in:
Daniel Mevec 2023-02-12 16:29:25 +01:00
parent 4151d2489f
commit 2c44bae0da

View file

@ -1,6 +1,7 @@
import numpy as np import numpy as np
from numpy.polynomial.polynomial import Polynomial from numpy.polynomial.polynomial import Polynomial
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.widgets import Slider, Button from matplotlib.widgets import Slider, Button
@ -77,7 +78,7 @@ class TorusWorld:
return np.allclose(self.surface_point(phi, theta), self.sun+roots[0]*ray) return np.allclose(self.surface_point(phi, theta), self.sun+roots[0]*ray)
def illumination(self, phi, theta): def illumination(self, phi, theta):
return np.dot(self.ray_vector(phi, theta), -self.normal_vector(phi, theta)) * self.is_illuminated(phi, theta) return np.dot(self.ray_vector(phi, theta), -self.normal_vector(phi, theta)) # * self.is_illuminated(phi, theta)
class NoInamge(): class NoInamge():
@ -100,7 +101,7 @@ class NoInamge():
self.ax.set_aspect('equal') self.ax.set_aspect('equal')
self.ax.axis('off') self.ax.axis('off')
self.init_top_view() self.init_top_view()
self.init_side_view() self.init_side_view()
self.init_map_view() self.init_map_view()
@ -258,9 +259,7 @@ class NoInamge():
return x, z+self._offset_side() return x, z+self._offset_side()
def redraw_plot(self, line, func): def redraw_plot(self, line, func):
x, y = func() line.set_data(*func())
line.set_xdata(x)
line.set_ydata(y)
self.ax.relim() self.ax.relim()
self.ax.autoscale_view() self.ax.autoscale_view()
@ -357,11 +356,20 @@ class ImageInteractive(NoInamge):
class AnimatedImage(NoInamge): class AnimatedImage(NoInamge):
def __init__(self, rfrac_init=0.5, sun_init=np.pi/2): def __init__(self, rfrac_init=0.5, sun_init=-np.pi):
super().__init__(rfrac_init, sun_init) super().__init__(rfrac_init, sun_init)
self.ani = animation.FuncAnimation(self.fig, self.animate, frames=150)
plt.show() plt.show()
def animate(self, frame_i):
phi = (frame_i*2*np.pi/150)-np.pi
self.update_sun(phi, 0)
return self.lines.values()
if __name__ == '__main__': if __name__ == '__main__':
# ImageStatic() # ImageStatic()
ImageInteractive() # ImageInteractive()
AnimatedImage()