import numpy as np
import matplotlib.pyplot as plt
theta = np.linspace(0, 20 * np.pi, 2000)
radius = np.linspace(0, 10, 2000)
x = radius * np.cos(theta)
y = radius * np.sin(theta)
x += 0.5 * np.sin(10 * theta)
y += 0.5 * np.cos(10 * theta)
plt.figure(figsize=(8, 8))
plt.plot(x, y, color='purple', linewidth=1)
plt.axis('off')
plt.gca().set_aspect('equal', adjustable='box')
plt.title('Swirl Bloom Pattern')
plt.show()
#source code --> clcoding.com
Code Explanation:
1. Importing Libraries
import numpy as np
import matplotlib.pyplot as plt
NumPy is used for mathematical operations,
especially for generating arrays using linspace and performing trigonometric
calculations.
Matplotlib is used for plotting the pattern using
plt.plot().
2. Generating the Swirl with Parametric Equations
theta = np.linspace(0, 20 * np.pi, 2000)
radius = np.linspace(0, 10, 2000)
theta: This is the angle in radians, ranging from 0
to 20π.
20 * np.pi means the spiral will have 10 complete
turns (since one complete turn is 2π).
2000 points ensure a smooth and continuous curve.
radius: This linearly increases from 0 to 10,
creating an outward bloom effect.
3. Creating the Swirl Shape
x = radius * np.cos(theta)
y = radius * np.sin(theta)
Parametric Equations:
x=r⋅cos(θ)
y=r⋅sin(θ)
These equations generate a spiral by gradually
increasing the radius while rotating around the center.
4. Adding a Wavy Distortion
x += 0.5 * np.sin(10 * theta)
y += 0.5 * np.cos(10 * theta)
This introduces a wave-like perturbation to the
spiral, making it bloom or ripple.
np.sin(10 * theta) and np.cos(10 * theta) add
oscillations to both the x and y coordinates.
The factor 10 controls the number of small wave ripples
(10 cycles per spiral).
The amplitude 0.5 controls the size of the
distortions.
This gives the pattern a swirling, blooming effect.
5. Plotting the Pattern
plt.figure(figsize=(8, 8))
plt.plot(x, y, color='purple', linewidth=1)
plt.figure(figsize=(8, 8)): Creates a square figure
with a size of 8x8 inches.
plt.plot(): Plots the x and y coordinates with a
purple color and a thin line (linewidth=1).
6. Adjusting Aesthetics
plt.axis('off')
plt.gca().set_aspect('equal', adjustable='box')
plt.title('Swirl Bloom Pattern')
plt.show()
plt.axis('off'): Hides the axis for a cleaner look.
plt.gca().set_aspect('equal', adjustable='box'):
Maintains the aspect ratio to ensure the bloom shape is not distorted.
plt.title(): Displays the title.
plt.show(): Renders the plot.
0 Comments:
Post a Comment