Skip to content

Instantly share code, notes, and snippets.

@trickre
Created January 17, 2018 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trickre/e5876efa4b3cecba106b93f734c3d54c to your computer and use it in GitHub Desktop.
Save trickre/e5876efa4b3cecba106b93f734c3d54c to your computer and use it in GitHub Desktop.
plot Spirograph
'''
making spirograph
'''
import matplotlib.pyplot as plt
import numpy as np
def main():
#plot
raws = 1
figure = plt.figure(num=None, figsize=(10,10), dpi=80, facecolor='w', edgecolor='b')
panel1 = figure.add_subplot(raws,1,1)
panel1.set_title("spirograph")
x,y = get_spirograph()
panel1.plot(x,y)
plt.show()
def get_spirograph():
x = []
y = []
for idx in range(100000):
n = 50
h = 100
x.append(func_x(t_radian(idx),n,h))
y.append(func_y(t_radian(idx),n,h))
return x,y
def func_x(t,n,h):
ans = 0
ans = ((n-1)*np.cos(t) + h*np.cos((n-1)*t))/n
return ans
def func_y(t,n,h):
ans = 0
ans = ((n-1)*np.sin(t) + h*np.sin((n-1)*t))/n
return ans
def t_radian(index):
rad = 0
devide_point = 720
rad = (index*2*np.pi)/devide_point
return rad
if (__name__ == '__main__'):
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment