Created
January 17, 2018 12:57
-
-
Save trickre/e5876efa4b3cecba106b93f734c3d54c to your computer and use it in GitHub Desktop.
plot Spirograph
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
''' | |
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