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
from numpy.polynomial.polynomial import Polynomial
import matplotlib.pyplot as plt
import matplotlib.animation as animation
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)
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():
@ -258,9 +259,7 @@ class NoInamge():
return x, z+self._offset_side()
def redraw_plot(self, line, func):
x, y = func()
line.set_xdata(x)
line.set_ydata(y)
line.set_data(*func())
self.ax.relim()
self.ax.autoscale_view()
@ -357,11 +356,20 @@ class ImageInteractive(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)
self.ani = animation.FuncAnimation(self.fig, self.animate, frames=150)
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__':
# ImageStatic()
ImageInteractive()
# ImageInteractive()
AnimatedImage()