Tuesday, 20 May 2025

Chrono Web Pattern using Python

 


import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

r = np.linspace(0.1, 5, 200)

theta = np.linspace(0, 2 * np.pi, 200)

r, theta = np.meshgrid(r, theta)

X = r * np.cos(theta)

Y = r * np.sin(theta)

Z = np.sin(4 * theta - 2 * r) * np.exp(-0.1 * r)

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

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

ax.plot_surface(X, Y, Z, cmap='viridis', edgecolor='black', linewidth=0.1)

ax.set_title('Chrono Web', fontsize=18, fontweight='bold')

ax.axis('off')

ax.view_init(elev=30, azim=45)

plt.tight_layout()

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 is used for numerical operations, especially for creating arrays and mathematical functions.
matplotlib.pyplot is the plotting library used for visualization.
mpl_toolkits.mplot3d enables 3D plotting capabilities in matplotlib.

2. Create the Polar Grid
r = np.linspace(0.1, 5, 200)
theta = np.linspace(0, 2 * np.pi, 200)
r, theta = np.meshgrid(r, theta)
r (radius) goes from 0.1 to 5 in 200 steps.
theta (angle) goes from 0 to 2π (a full circle) in 200 steps.
np.meshgrid creates a 2D grid from these vectors, so we can calculate X, Y, and Z values over the full polar coordinate system.

3. Convert Polar Coordinates to Cartesian
X = r * np.cos(theta)
Y = r * np.sin(theta)
Converts each point in the polar grid into Cartesian coordinates.
This is needed because matplotlib 3D plots are in X-Y-Z space.

4. Define Z Values (Height) – the "Chrono Web" Pattern
Z = np.sin(4 * theta - 2 * r) * np.exp(-0.1 * r)
This formula creates radial sine wave ripples.
4 * theta gives a rotational (angular) ripple with 4 waves per rotation.
-2 * r makes the wave shift inward or outward, creating a spiraling effect.
np.exp(-0.1 * r) damps the wave amplitude as the radius increases — simulating fading over distance, like time decay.

5. Set Up the Plot
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
fig = plt.figure(...) creates the figure window with a specific size.
add_subplot(..., projection='3d') initializes a 3D plot.

6. Draw the Surface
ax.plot_surface(X, Y, Z, cmap='viridis', edgecolor='black', linewidth=0.1)
plot_surface draws a 3D surface.
cmap='viridis' gives a smooth color gradient.
edgecolor='black', linewidth=0.1 adds a subtle grid to give a web-like structure.

7. Customize the Plot
ax.set_title('Chrono Web', fontsize=18, fontweight='bold')
ax.axis('off')
ax.view_init(elev=30, azim=45)
set_title(...) adds a bold title to the plot.
axis('off') hides the axes for a cleaner, more artistic look.
view_init(...) sets the camera angle (elevation = 30°, azimuth = 45°) for 3D viewing.

8. Final Layout and Display
plt.tight_layout()
plt.show()
tight_layout() adjusts the spacing to fit all elements nicely.
plt.show() renders the plot window and displays the final "Chrono Web" 3D pattern.

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (118) AI (152) Android (25) AngularJS (1) Api (6) Assembly Language (2) aws (27) Azure (8) BI (10) Books (251) Bootcamp (1) C (78) C# (12) C++ (83) Course (84) Coursera (298) Cybersecurity (28) Data Analysis (24) Data Analytics (16) data management (15) Data Science (217) Data Strucures (13) Deep Learning (68) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (17) Finance (9) flask (3) flutter (1) FPL (17) Generative AI (47) Git (6) Google (47) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (186) Meta (24) MICHIGAN (5) microsoft (9) Nvidia (8) Pandas (11) PHP (20) Projects (32) Python (1218) Python Coding Challenge (884) Python Quiz (342) Python Tips (5) Questions (2) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (45) Udemy (17) UX Research (1) web application (11) Web development (7) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)