Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import partial
- import matplotlib.pyplot as plt
- import numpy as np
- from IPython.display import HTML
- from matplotlib.animation import FuncAnimation
- plt.style.use("ggplot")
- figure, axis = plt.subplots(figsize=(9, 9))
- axis: plt.Axes
- axis.set_xlim(-4.5, 4.5)
- axis.set_ylim(-4.5, 4.5)
- class FrameUpdater:
- def __init__(
- self,
- axis: plt.Axes,
- limit: float,
- frequency: int,
- ) -> None:
- self.axis = axis
- self.limit = limit
- self.frequency = frequency
- self.waves: list[plt.Circle] = []
- self.add_wave()
- def __call__(self, frame_id: int) -> list[plt.Circle]:
- if frame_id == 0:
- return self.waves
- new_waves = []
- for wave in self.waves:
- wave.set_radius(wave.radius + 0.1)
- if wave.radius > self.limit:
- wave.remove()
- else:
- new_waves.append(wave)
- self.waves = new_waves
- if frame_id % self.frequency == 0:
- self.add_wave()
- return self.waves
- def add_wave(self):
- wave = plt.Circle((0, 0), 0, fill=False, lw=2, color = 'b')
- self.axis.add_patch(wave)
- self.waves.append(wave)
- animation = FuncAnimation(
- figure,
- FrameUpdater(
- axis=axis,
- limit=4.5,
- frequency=10,
- ),
- frames=100,
- interval=50,
- blit=True,
- )
- HTML(animation.to_jshtml())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement