Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import plotly.graph_objects as go
|
4 |
+
|
5 |
+
st.title('Plant Fractal')
|
6 |
+
|
7 |
+
def generate_strange_attractor(num_points, a, b, c, d):
|
8 |
+
x, y, z = 0.1, 0.0, 0.0
|
9 |
+
points = []
|
10 |
+
for i in range(num_points):
|
11 |
+
x_dot = np.sin(y * a) - np.cos(x * b)
|
12 |
+
y_dot = np.sin(z * c) - np.cos(y * a)
|
13 |
+
z_dot = np.sin(x * d) - np.cos(z * c)
|
14 |
+
x += 0.1 * x_dot
|
15 |
+
y += 0.1 * y_dot
|
16 |
+
z += 0.1 * z_dot
|
17 |
+
points.append((x, y, z))
|
18 |
+
x, y, z = zip(*points)
|
19 |
+
return go.Scatter3d(x=x, y=y, z=z, mode='lines', line=dict(width=1))
|
20 |
+
|
21 |
+
def generate_julia_set(num_points, c):
|
22 |
+
def f(z, c):
|
23 |
+
return z**2 + c
|
24 |
+
x, y, z = np.zeros(num_points), np.zeros(num_points), np.zeros(num_points)
|
25 |
+
for i in range(1, num_points):
|
26 |
+
x[i], y[i], z[i] = f((x[i-1], y[i-1], z[i-1]), c)
|
27 |
+
return go.Scatter3d(x=x, y=y, z=z, mode='lines', line=dict(width=1))
|
28 |
+
|
29 |
+
num_points = st.slider('How many points do you want to generate?', 1000, 100000, 10000)
|
30 |
+
fractal_type = st.selectbox('Select a fractal type', ('Strange Attractor', 'Julia Set'))
|
31 |
+
|
32 |
+
if fractal_type == 'Strange Attractor':
|
33 |
+
a = st.slider('a', 0.0, 2.0, 1.2)
|
34 |
+
b = st.slider('b', 0.0, 2.0, 0.6)
|
35 |
+
c = st.slider('c', 0.0, 2.0, 1.7)
|
36 |
+
d = st.slider('d', 0.0, 2.0, 1.5)
|
37 |
+
fig = go.Figure(generate_strange_attractor(num_points, a, b, c, d))
|
38 |
+
fig.update_layout(
|
39 |
+
title='Strange Attractor Fractal',
|
40 |
+
scene=dict(
|
41 |
+
xaxis_title='X',
|
42 |
+
yaxis_title='Y',
|
43 |
+
zaxis_title='Z'
|
44 |
+
),
|
45 |
+
showlegend=False
|
46 |
+
)
|
47 |
+
else:
|
48 |
+
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))
|
49 |
+
fig = go.Figure(generate_julia_set(num_points, c))
|
50 |
+
fig.update_layout(
|
51 |
+
title='Julia Set Fractal',
|
52 |
+
scene=dict(
|
53 |
+
xaxis_title='X',
|
54 |
+
yaxis_title='Y',
|
55 |
+
zaxis_title='Z'
|
56 |
+
),
|
57 |
+
showlegend=False
|
58 |
+
)
|
59 |
+
|
60 |
+
st.plotly_chart(fig)
|