awacke1 commited on
Commit
ce4c136
·
1 Parent(s): f2ae676

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import numpy as np
3
- import plotly.graph_objects as go
 
4
 
5
  st.title('Plant Fractal')
6
 
@@ -16,15 +17,16 @@ def generate_strange_attractor(num_points, a, b, c, d):
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'))
@@ -34,27 +36,25 @@ if fractal_type == 'Strange Attractor':
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)
 
1
  import streamlit as st
2
  import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
 
6
  st.title('Plant Fractal')
7
 
 
17
  z += 0.1 * z_dot
18
  points.append((x, y, z))
19
  x, y, z = zip(*points)
20
+ return (x, y, z)
21
 
22
  def generate_julia_set(num_points, c):
23
  def f(z, c):
24
  return z**2 + c
25
  x, y, z = np.zeros(num_points), np.zeros(num_points), np.zeros(num_points)
26
+ z[0] = 1
27
  for i in range(1, num_points):
28
  x[i], y[i], z[i] = f((x[i-1], y[i-1], z[i-1]), c)
29
+ return (x, y, z)
30
 
31
  num_points = st.slider('How many points do you want to generate?', 1000, 100000, 10000)
32
  fractal_type = st.selectbox('Select a fractal type', ('Strange Attractor', 'Julia Set'))
 
36
  b = st.slider('b', 0.0, 2.0, 0.6)
37
  c = st.slider('c', 0.0, 2.0, 1.7)
38
  d = st.slider('d', 0.0, 2.0, 1.5)
39
+ x, y, z = generate_strange_attractor(num_points, a, b, c, d)
40
+ fig = plt.figure()
41
+ ax = fig.add_subplot(111, projection='3d')
42
+ sns.lineplot(x=x, y=y, z=z, ax=ax, linewidth=1)
43
+ ax.set_title('Strange Attractor Fractal')
44
+ ax.set_xlabel('X')
45
+ ax.set_ylabel('Y')
46
+ ax.set_zlabel('Z')
47
+ st.pyplot(fig)
 
48
  else:
49
+ real_part = st.slider('Real part of c', -2.0, 2.0, 0.4)
50
+ imag_part = st.slider('Imaginary part of c', -2.0, 2.0, 0.1)
51
+ c = complex(real_part, imag_part)
52
+ x, y, z = generate_julia_set(num_points, c)
53
+ fig = plt.figure()
54
+ ax = fig.add_subplot(111, projection='3d')
55
+ sns.lineplot(x=x, y=y, z=z, ax=ax, linewidth=1)
56
+ ax.set_title('Julia Set Fractal')
57
+ ax.set_xlabel('X')
58
+ ax.set_ylabel('Y')
59
+ ax.set_zlabel('Z')
60
+ st.pyplot(fig)