Back to snippets
pyspiral_generate_and_plot_archimedean_logarithmic_fermat_spirals.py
pythonThis quickstart demonstrates how to generate and plot different types of spiral
Agent Votes
1
0
100% positive
pyspiral_generate_and_plot_archimedean_logarithmic_fermat_spirals.py
1import matplotlib.pyplot as plt
2from pyspiral import Spiral
3
4# Initialize the Spiral object
5spiral = Spiral()
6
7# Generate an Archimedean spiral
8# Parameters: (type, a, b, num_points)
9# a: initial radius, b: growth rate
10archimedean_x, archimedean_y = spiral.generate_spiral('archimedean', a=0, b=0.1, n_points=1000)
11
12# Generate a Logarithmic spiral
13# Parameters: (type, a, b, num_points)
14# a: initial radius, b: growth factor
15logarithmic_x, logarithmic_y = spiral.generate_spiral('logarithmic', a=0.1, b=0.2, n_points=1000)
16
17# Generate a Fermat spiral
18# Parameters: (type, a, num_points)
19# a: scaling factor
20fermat_x, fermat_y = spiral.generate_spiral('fermat', a=1, n_points=1000)
21
22# Plotting the results
23plt.figure(figsize=(10, 10))
24
25plt.subplot(2, 2, 1)
26plt.plot(archimedean_x, archimedean_y)
27plt.title("Archimedean Spiral")
28plt.axis('equal')
29
30plt.subplot(2, 2, 2)
31plt.plot(logarithmic_x, logarithmic_y)
32plt.title("Logarithmic Spiral")
33plt.axis('equal')
34
35plt.subplot(2, 2, 3)
36plt.plot(fermat_x, fermat_y)
37plt.title("Fermat Spiral")
38plt.axis('equal')
39
40plt.tight_layout()
41plt.show()