awacke1 commited on
Commit
bdcd960
·
1 Parent(s): 6ea69d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -17
app.py CHANGED
@@ -18,19 +18,36 @@ def generate_strange_attractor(num_points, a, b, c, d):
18
  x, y, z = zip(*points)
19
  return (x, y, z)
20
 
21
- def generate_julia_set(num_points, c):
22
- def f(z, c):
23
- return z[0]**2 - z[1]**2 + c[0], 2*z[0]*z[1] + c[1]
24
- x, y, z = np.zeros(num_points), np.zeros(num_points), np.zeros((num_points, 2))
25
- z[0] = (1, 1)
26
- i = 1
27
- while i < num_points:
28
- x[i], y[i], z[i] = f(z[i-1], c)
29
- i += 1
30
- return (x, y, z[:, 0])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  num_points = st.slider('How many points do you want to generate?', 1000, 100000, 10000)
33
- fractal_type = st.selectbox('Select a fractal type', ('Strange Attractor', 'Julia Set'))
34
 
35
  if fractal_type == 'Strange Attractor':
36
  a = st.slider('a', 0.0, 2.0, 1.2)
@@ -46,13 +63,36 @@ if fractal_type == 'Strange Attractor':
46
  ax.set_ylabel('Y')
47
  ax.set_zlabel('Z')
48
  st.pyplot(fig)
49
- else:
50
- real_part = st.slider('Real part of c', -2.0, 2.0, 0.4)
51
- imag_part = st.slider('Imaginary part of c', -2.0, 2.0, 0.1)
52
- c = (real_part, imag_part)
53
- x, y, z = generate_julia_set(num_points, c)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  fig = plt.figure()
55
  ax = fig.add_subplot(111, projection='3d')
56
  ax.plot(x, y, z, linewidth=1)
57
- ax.set_title('Julia Set Fractal')
58
  ax.set_xlabel('X')
 
 
 
 
 
 
 
18
  x, y, z = zip(*points)
19
  return (x, y, z)
20
 
21
+ def generate_fractal_1(num_points, a, b, c, d):
22
+ x, y, z = 0.0, 0.0, 0.0
23
+ points = []
24
+ for i in range(num_points):
25
+ x_dot = np.sin(a * y) - np.sin(b * x)
26
+ y_dot = np.sin(c * x) - np.sin(d * y)
27
+ z_dot = 0.2
28
+ x += x_dot
29
+ y += y_dot
30
+ z += z_dot
31
+ points.append((x, y, z))
32
+ x, y, z = zip(*points)
33
+ return (x, y, z)
34
+
35
+ def generate_fractal_2(num_points, a, b, c, d):
36
+ x, y, z = 0.1, 0.0, 0.0
37
+ points = []
38
+ for i in range(num_points):
39
+ x_dot = np.sin(y * a) - np.cos(x * b)
40
+ y_dot = np.sin(z * c) - np.cos(y * a)
41
+ z_dot = np.sin(x * d) - np.cos(z * c)
42
+ x += 0.2 * x_dot
43
+ y += 0.2 * y_dot
44
+ z += 0.2 * z_dot
45
+ points.append((x, y, z))
46
+ x, y, z = zip(*points)
47
+ return (x, y, z)
48
 
49
  num_points = st.slider('How many points do you want to generate?', 1000, 100000, 10000)
50
+ fractal_type = st.selectbox('Select a fractal type', ('Strange Attractor', 'Fractal 1', 'Fractal 2'))
51
 
52
  if fractal_type == 'Strange Attractor':
53
  a = st.slider('a', 0.0, 2.0, 1.2)
 
63
  ax.set_ylabel('Y')
64
  ax.set_zlabel('Z')
65
  st.pyplot(fig)
66
+
67
+ if fractal_type == 'Fractal 1':
68
+ a = st.slider('a', 0.0, 2.0, 1.2)
69
+ b = st.slider('b', 0.0, 2.0, 0.6)
70
+ c = st.slider('c', 0.0, 2.0, 1.7)
71
+ d = st.slider('d', 0.0, 2.0, 1.5)
72
+ x, y, z = generate_fractal_1(num_points, a, b, c, d)
73
+ fig = plt.figure()
74
+ ax = fig.add_subplot(111, projection='3d')
75
+ ax.plot(x, y, z, linewidth=1)
76
+ ax.set_title('Fractal 1')
77
+ ax.set_xlabel('X')
78
+ ax.set_ylabel('Y')
79
+ ax.set_zlabel('Z')
80
+ st.pyplot(fig)
81
+
82
+ if fractal_type == 'Fractal 2':
83
+ a = st.slider('a', 0.0, 2.0, 1.2)
84
+ b = st.slider('b', 0.0, 2.0, 0.6)
85
+ c = st.slider('c', 0.0, 2.0, 1.7)
86
+ d = st.slider('d', 0.0, 2.0, 1.5)
87
+ x, y, z = generate_fractal_2(num_points, a, b, c, d)
88
  fig = plt.figure()
89
  ax = fig.add_subplot(111, projection='3d')
90
  ax.plot(x, y, z, linewidth=1)
91
+ ax.set_title('Fractal 2')
92
  ax.set_xlabel('X')
93
+ ax.set_ylabel('Y')
94
+ ax.set_zlabel('Z')
95
+ st.pyplot(fig)
96
+
97
+
98
+