Skip to content

Instantly share code, notes, and snippets.

@telday
Last active March 25, 2022 03:17
Show Gist options
  • Save telday/744a7854198b1813e38646098c26be56 to your computer and use it in GitHub Desktop.
Save telday/744a7854198b1813e38646098c26be56 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import matplotlib.animation as ani
import math
import time
fig = plt.figure()
def minkowsky(x, n):
y = (1-abs(x)**n)**(1 / n)
return (y, -1 * y)
def minkowsky_points(n):
x = [(i / 40.0) - 1 for i in range(0, 81)]
ypos, yneg = zip(*[minkowsky(i, n) for i in x])
return x + list(reversed(x)), list(ypos) + list(reversed(yneg))
artists = list()
for i in range(0, 30, 1):
ax = fig.add_subplot()
ax.set_title(f"Minkowsky {round(i / 10 + 0.1, 2)} Unit Circle")
ax.grid(visible=True, color='k', linewidth=0.5)
ax.set_aspect('equal')
ticks = [i / 4 - 1 for i in range(9)]
ax.set_xticks(ticks)
x, y = minkowsky_points(i/10 + 0.1)
line = ax.plot(x, y, 'r-')
artists.append([ax])
artists += list(reversed(artists))
animator = ani.ArtistAnimation(fig, artists)
plt.show()
animator.save('output.gif')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment