English: ```python
import numpy as np
def dynamical_system(x, y, z, a, b, n_iter):
x_values = np.empty(n_iter)
y_values = np.empty(n_iter)
z_values = np.empty(n_iter)
x_values[0] = x
y_values[0] = y
z_values[0] = z
for i in range(1, n_iter):
x, y, z = x_values[i], y_values[i], z_values[i] = a * x * (1 - x) - 0.05 * (y + 0.35) * (1 - 2 * z), 0.1 * ((y + 0.35) * (1 + 2 * z) - 1) * (1 - 1.9 * x), 3.78 * z * (1 - z) + b * y
return x_values, y_values, z_values
- Parameters
a = 3.8
b = 0.2
x_init = 0.085
y_init = -0.121
z_init = 0.075
n_iter = 800000
x, y, z = dynamical_system(x_init, y_init, z_init, a, b, n_iter)
init_time = 1000
def normalize(x):
a, b = np.quantile(x, 0.999), np.quantile(x, 0.001)
return 2 * (x - (a+b)/2) / (a - b)
x = normalize(x)[init_time:]
y = normalize(y)[init_time:]
z = normalize(z)[init_time:]
print(min(x), max(x), min(y), max(y), min(z), max(z))
%%capture
import matplotlib.pyplot as plt
import numpy as np
import os
for i, theta in enumerate( np.linspace(0, 2*np.pi, 120)):
fig, ax = plt.subplots(figsize=(20, 20))
init_time = 1000
ax.scatter(y*np.cos(theta) + z*np.sin(theta), x, color='k', s=0.005)
ax.axis("off")
ax.set_xlim(-1.06, 1.06)
ax.set_ylim(-1.03, 1.03)
dir_path = f"./towel"
if not os.path.exists(dir_path):
os.makedirs(dir_path)
fig.savefig(f"{dir_path}/{i}.png")
plt.close()
import imageio.v3 as iio
import os
from natsort import natsorted
import moviepy.editor as mp
for dir_path in ["./towel"]:
file_names = natsorted((fn for fn in os.listdir(dir_path) if fn.endswith('.png')))
# Create a list of image files and set the frame rate
images = []
fps = 12
# Iterate over the file names and append the images to the list
for file_name in file_names:
file_path = os.path.join(dir_path, file_name)
images.append(iio.imread(file_path))
filename = dir_path[2:]
iio.imwrite(f"{filename}.gif", images, duration=1000/fps, rewind=True)
clip = mp.ImageSequenceClip(images, fps=fps)
clip.write_videofile(f"{filename}.mp4")
```