import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
theta = np.linspace(0, 25 * np.pi, 1500)
z = np.linspace(-4, 4, 1500)
r = 1 / (z**2 + 1) + 0.5
x = r * np.sin(theta)
y = r * np.cos(theta)
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, z, color='lime', linewidth=2)
ax.scatter(x, y, z, c=theta, cmap='cool', s=2)
ax.set_title('Wormhole Twist 3D Pattern', fontsize=18, color='white')
ax.set_facecolor('black')
fig.patch.set_facecolor('black')
ax.grid(False)
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
plt.show()
#source code --> clcoding.com
Code Explanation:
1. Importing Libraries
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
numpy → For numerical calculations.
a) Theta → Angle for Rotation
theta = np.linspace(0, 25 * np.pi, 1500)
Generates 1500 values from 0 to 25π.
z = np.linspace(-4, 4, 1500)
Generates 1500 points from -4 to 4.
r = 1 / (z**2 + 1) + 0.5
Formula gives a shape of a wormhole or funnel.
x = r * np.sin(theta)
y = r * np.cos(theta)
Converts from (r, θ) to (x, y) for 3D plotting.
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111, projection='3d')
Creates the figure and 3D axis.
5. Plotting the Wormhole Spiral Line
ax.plot(x, y, z, color='lime', linewidth=2)
Draws the spiral line.
ax.scatter(x, y, z, c=theta, cmap='cool', s=2)
Adds tiny dots along the spiral line.
Looks like energy particles swirling around the
wormhole.
ax.set_title('Wormhole Twist 3D Pattern',
fontsize=18, color='white')
ax.set_facecolor('black')
fig.patch.set_facecolor('black')
ax.grid(False)
Adds the title in white color.
Sets background color to black for a space-like look.
Removes grid lines.
8. Removing Axis Ticks
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
Hides x, y, z axis numbers for a clean visual
design.
9. Display the Final 3D Plot
plt.show()
Displays the 3D plot.


0 Comments:
Post a Comment