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.


Related Posts:

  • Find LCM in Python # Python Program to find the L.C.M. of two input number # define a function def lcm(x, y): """This function takes two integers and returns the L.C… Read More
  • Decimal to Binary in Python #Python program to convert decimal number into binary, octal and hexadecimal number system # Change this line for a different result dec = 344 prin… Read More
  • ASCII value of character in Python #Program to find the ASCII value of the given character # Change this value for a different result c = 'p' # Uncomment to take character from user … Read More
  • Find the Hash of File in Python # Python rogram to find the SHA-1 message digest of a file # import hashlib module import hashlib def hash_file(filename): """"This function return… Read More
  • Find HCF to GCD in Python # Python program to find the H.C.F of two input number # define a function def computeHCF(x, y): # choose the smaller number if x > y: smaller… Read More

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 (37) 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 (1066) Python Coding Challenge (465) Python Quiz (136) 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)