Saturday, 12 April 2025

Plasma Whirl 3D Pattern using Python

 


import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

theta = np.linspace(0, 15 * np.pi, 1000)  

z = np.linspace(-3, 3, 1000)              

r = np.abs(np.sin(5 * z)) + 0.5

x = r * np.cos(theta)

y = r * np.sin(theta)

fig = plt.figure(figsize=(6, 6))

ax = fig.add_subplot(111, projection='3d')

ax.plot(x, y, z, color='magenta', linewidth=2)

ax.scatter(x, y, z, c=np.abs(z), cmap='plasma', s=2)

ax.set_title('Plasma Whirl 3D Pattern', fontsize=18, color='yellow')

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 Required Libraries

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

numpy → For mathematical operations and creating data points.

 matplotlib.pyplot → For plotting the graph.

 Axes3D → To enable 3D plotting.

 2. Creating Data for the Spiral Structure

a) Angle Values for Rotation

theta = np.linspace(0, 15 * np.pi, 1000)

Creates values from 0 to 15π (about 7.5 full rotations).

 Controls the circular rotation of the plot.

 b) Z-Axis Values for Height

z = np.linspace(-3, 3, 1000)

Creates points from -3 to 3.

 Controls the vertical spread of the spiral.

 c) Radius for Distance from Center

r = np.abs(np.sin(5 * z)) + 0.5

Radius is dynamic, based on a sine wave of z.

 5 * z → Controls the frequency of waves.

 np.abs() → Ensures radius is always positive.

 +0.5 → Minimum radius to avoid collapse to center.

 This makes the radius oscillate — creating a whirl or spiral wave effect.

 3. Converting to Cartesian Coordinates

x = r * np.cos(theta)

y = r * np.sin(theta)

Converts polar coordinates (r, θ) to Cartesian (x, y) for 3D plotting.

 4. Creating the Plotting Environment

fig = plt.figure(figsize=(10, 7))

ax = fig.add_subplot(111, projection='3d')

Sets the plot size.

 Adds a 3D plot axis.

 5. Plotting the Spiral Line (Main Structure)

ax.plot(x, y, z, color='magenta', linewidth=2)

Draws the spiral line.

 Color → magenta.

 Line thickness → 2.

 6. Adding Scatter Dots (Plasma Energy Effect)

ax.scatter(x, y, z, c=np.abs(z), cmap='plasma', s=2)

Adds glowing dots along the spiral.

 c=np.abs(z) → Color of dots depends on z height.

 cmap='plasma' → Plasma color gradient (yellow-pink-purple).

 s=2 → Size of the dots.

 This gives it the "energy plasma" vibe.

 7. Styling the Plot

ax.set_title('Plasma Whirl 3D Pattern', fontsize=18, color='yellow')

ax.set_facecolor('black')

fig.patch.set_facecolor('black')

ax.grid(False)

Title in yellow color.

 Black background for clean and futuristic look.

 No grid lines for simplicity.

 8. Removing Axis Ticks

ax.set_xticks([])

ax.set_yticks([])

ax.set_zticks([])

Hides x, y, z axis ticks for a pure design look.

 9. Display the Final 3D Plot

plt.show()

Shows the final plot.


0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (108) AI (41) Android (24) AngularJS (1) Api (2) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (200) C (77) C# (12) C++ (83) Course (67) Coursera (253) Cybersecurity (25) Data Analysis (3) Data Analytics (4) data management (11) Data Science (149) Data Strucures (8) Deep Learning (21) Django (16) Downloads (3) edx (2) Engineering (14) Euron (29) Events (6) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Generative AI (11) Google (38) Hadoop (3) HTML Quiz (1) HTML&CSS (47) IBM (30) IoT (1) IS (25) Java (93) Java quiz (1) Leet Code (4) Machine Learning (86) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (4) Pandas (4) PHP (20) Projects (29) pyth (1) Python (1067) Python Coding Challenge (465) Python Quiz (137) Python Tips (5) Questions (2) R (70) React (6) Scripting (3) security (3) Selenium Webdriver (4) Software (17) SQL (42) UX Research (1) web application (8) Web development (4) web scraping (2)

Followers

Python Coding for Kids ( Free Demo for Everyone)