import streamlit as st import numpy as np import matplotlib.pyplot as plt st.title('Plant Fractal') def generate_strange_attractor(num_points, a, b, c, d): x, y, z = 0.1, 0.0, 0.0 points = [] for i in range(num_points): x_dot = np.sin(y * a) - np.cos(x * b) y_dot = np.sin(z * c) - np.cos(y * a) z_dot = np.sin(x * d) - np.cos(z * c) x += 0.1 * x_dot y += 0.1 * y_dot z += 0.1 * z_dot points.append((x, y, z)) x, y, z = zip(*points) return (x, y, z) def generate_fractal_1(num_points, a, b, c, d): x, y, z = 0.0, 0.0, 0.0 points = [] for i in range(num_points): x_dot = np.sin(a * y) - np.sin(b * x) y_dot = np.sin(c * x) - np.sin(d * y) z_dot = 0.2 x += x_dot y += y_dot z += z_dot points.append((x, y, z)) x, y, z = zip(*points) return (x, y, z) def generate_fractal_2(num_points, a, b, c, d): x, y, z = 0.1, 0.0, 0.0 points = [] for i in range(num_points): x_dot = np.sin(y * a) - np.cos(x * b) y_dot = np.sin(z * c) - np.cos(y * a) z_dot = np.sin(x * d) - np.cos(z * c) x += 0.2 * x_dot y += 0.2 * y_dot z += 0.2 * z_dot points.append((x, y, z)) x, y, z = zip(*points) return (x, y, z) num_points = st.slider('How many points do you want to generate?', 1000, 100000, 10000) fractal_type = st.selectbox('Select a fractal type', ('Strange Attractor', 'Fractal 1', 'Fractal 2')) if fractal_type == 'Strange Attractor': a = st.slider('a', 0.0, 2.0, 1.2) b = st.slider('b', 0.0, 2.0, 0.6) c = st.slider('c', 0.0, 2.0, 1.7) d = st.slider('d', 0.0, 2.0, 1.5) x, y, z = generate_strange_attractor(num_points, a, b, c, d) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot(x, y, z, linewidth=1) ax.set_title('Strange Attractor Fractal') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') st.pyplot(fig) if fractal_type == 'Fractal 1': a = st.slider('a', 0.0, 2.0, 1.2) b = st.slider('b', 0.0, 2.0, 0.6) c = st.slider('c', 0.0, 2.0, 1.7) d = st.slider('d', 0.0, 2.0, 1.5) x, y, z = generate_fractal_1(num_points, a, b, c, d) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot(x, y, z, linewidth=1) ax.set_title('Fractal 1') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') st.pyplot(fig) if fractal_type == 'Fractal 2': a = st.slider('a', 0.0, 2.0, 1.2) b = st.slider('b', 0.0, 2.0, 0.6) c = st.slider('c', 0.0, 2.0, 1.7) d = st.slider('d', 0.0, 2.0, 1.5) x, y, z = generate_fractal_2(num_points, a, b, c, d) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot(x, y, z, linewidth=1) ax.set_title('Fractal 2') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') st.pyplot(fig)