import streamlit as st import numpy as np import plotly.graph_objects as go 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 go.Scatter3d(x=x, y=y, z=z, mode='lines', line=dict(width=1)) def generate_julia_set(num_points, c): def f(z, c): return z**2 + c x, y, z = np.zeros(num_points), np.zeros(num_points), np.zeros(num_points) for i in range(1, num_points): x[i], y[i], z[i] = f((x[i-1], y[i-1], z[i-1]), c) return go.Scatter3d(x=x, y=y, z=z, mode='lines', line=dict(width=1)) 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', 'Julia Set')) 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) fig = go.Figure(generate_strange_attractor(num_points, a, b, c, d)) fig.update_layout( title='Strange Attractor Fractal', scene=dict( xaxis_title='X', yaxis_title='Y', zaxis_title='Z' ), showlegend=False ) else: c = complex(st.slider('Real part of c', -2.0, 2.0, 0.4), st.slider('Imaginary part of c', -2.0, 2.0, 0.1)) fig = go.Figure(generate_julia_set(num_points, c)) fig.update_layout( title='Julia Set Fractal', scene=dict( xaxis_title='X', yaxis_title='Y', zaxis_title='Z' ), showlegend=False ) st.plotly_chart(fig)