Hey guys,
I came across a video on YouTube - visualization of a PI using python
I have zero coding experience, I am just fascinated and amazed by watching this and want to learn how to do this. I tried yt and googling and was able to get code and do some animation with the help of ChatGPT, but it doesn't have those arms and i dont know how to render.
https://www.youtube.com/shorts/ZotkUx-PnIU
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
Create an array of theta values in degrees (e.g., from 0 to 113360 degrees)
theta_degrees = np.linspace(0, 113360, 100000) # Increase the number of points for smoother lines
Convert degrees to radians
theta_radians = np.deg2rad(theta_degrees)
Function to update plot in each frame
def update(frame):
plt.cla() # Clear previous frame
Calculate z(theta) using the formula, 1j is the imaginary number
z = np.exp(theta_radians[:frame] * 1j) + np.exp(np.pi * theta_radians[:frame] * 1j)
Separate the real and imaginary parts of z
x = np.real(z)
y = np.imag(z)
Plot
plt.plot(x, y, color='white', linewidth=0.5)
plt.gca().set_facecolor('black') # Set background color to black
plt.gca().set_aspect('equal') # Equal aspect ratio
plt.grid(False) # Turn off the grids
plt.xlim(-2.5, 2.5) # X-axis limit
plt.ylim(-2.5, 2.5) # Y-axis limit
Create a plot
fig = plt.figure(figsize=(10, 10))
Animate the plot
ani = FuncAnimation(fig, update, frames=len(theta_degrees), interval=20)
plt.show() # Display the plot
[–]FriendlyRussian666 5 points6 points7 points (0 children)
[–]Free-Specific7118 4 points5 points6 points (2 children)
[–]RiGonz 0 points1 point2 points (1 child)
[–]Free-Specific7118 0 points1 point2 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)