Created
January 7, 2022 22:55
-
-
Save IlievskiV/6ff17af2a9d42fb3b9c212f881aca087 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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