-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspirograph.py
More file actions
executable file
·71 lines (56 loc) · 1.67 KB
/
Copy pathspirograph.py
File metadata and controls
executable file
·71 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
20201031
Times table
Links:
https://en.wikipedia.org/wiki/Spirograph
https://en.wikipedia.org/wiki/Hypocycloid
https://en.wikipedia.org/wiki/Deltoid_curve
https://en.wikipedia.org/wiki/Hypotrochoid
"""
from pathlib import Path
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
matplotlib.use("TkAgg")
def spirograph(
radius1=1.0,
radius2=0.6,
distance=1.2,
cycles=3,
number_of_control_points=300,
scale=True,
):
"""Spirograph
Args:
radius1 (float, optional): `Exterior` circle radius. Defaults to 1.0.
radius2 (float, optional): `Interior` circle radius. Defaults to 0.6.
distance (float, optional): Distance from the center of the `interior` circle. Defaults to 1.2.
cycles (float, optional): Full cycles. Defaults to 3.
number_of_control_points (int, optional): Number of control points. Defaults to 300.
scale (bool, optional): Scale points. Defaults to True.
Returns:
tuple: Points x, y.
"""
fi = np.linspace(0, cycles * 2 * np.pi, number_of_control_points)
r_difference = radius1 - radius2
x = r_difference * np.sin(fi) - distance * np.sin(
fi * r_difference / radius2
)
y = r_difference * np.cos(fi) + distance * np.cos(
fi * r_difference / radius2
)
if scale:
max_val = max([np.max(x), np.max(y)])
x *= 1 / max_val
y *= 1 / max_val
return x, y
if __name__ == "__main__":
x, y = spirograph(
radius1=1.0,
radius2=0.062,
distance=0.9,
cycles=3,
number_of_control_points=100,
)
plt.plot(x, y, c="k", linewidth=0.2)
plt.show()