Skip to content

Instantly share code, notes, and snippets.

@IlievskiV
Created January 7, 2022 22:55
Show Gist options
  • Save IlievskiV/6ff17af2a9d42fb3b9c212f881aca087 to your computer and use it in GitHub Desktop.
Save IlievskiV/6ff17af2a9d42fb3b9c212f881aca087 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def make_animation(sierpinski_triangle: list):
num_points = len(sierpinski_triangle)
points_split = list(zip(*sierpinski_triangle))
xx, yy = points_split[0], points_split[1]
fig = plt.figure(figsize=(10, 10))
def init():
ax = plt.axes(xlim=(0, 1), ylim=(0, 1))
ax.set_xticks([], [])
ax.set_yticks([], [])
ax.set_axis_off()
return ax.plot(xx, yy, "g.")
def animate(i):
scale = 1 - i * 0.02 # calculate the new scale
ax = plt.axes(xlim=(0, scale), ylim=(0, scale))
ax.set_xticks([], [])
ax.set_yticks([], [])
ax.set_axis_off()
return ax.plot(xx, yy, "g.")
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=50,
interval=200, blit=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment