awacke1 commited on
Commit
8c452a7
·
1 Parent(s): b406d52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -20,12 +20,12 @@ def generate_strange_attractor(num_points, a, b, c, d):
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
- z[0] = 1
26
  for i in range(1, num_points):
27
- x[i], y[i], z[i] = f((x[i-1], y[i-1], z[i-1]), c)
28
- return (x, y, z)
29
 
30
  num_points = st.slider('How many points do you want to generate?', 1000, 100000, 10000)
31
  fractal_type = st.selectbox('Select a fractal type', ('Strange Attractor', 'Julia Set'))
@@ -47,13 +47,10 @@ if fractal_type == 'Strange Attractor':
47
  else:
48
  real_part = st.slider('Real part of c', -2.0, 2.0, 0.4)
49
  imag_part = st.slider('Imaginary part of c', -2.0, 2.0, 0.1)
50
- c = complex(real_part, imag_part)
51
  x, y, z = generate_julia_set(num_points, c)
52
  fig = plt.figure()
53
  ax = fig.add_subplot(111, projection='3d')
54
  ax.plot(x, y, z, linewidth=1)
55
  ax.set_title('Julia Set Fractal')
56
  ax.set_xlabel('X')
57
- ax.set_ylabel('Y')
58
- ax.set_zlabel('Z')
59
- st.pyplot(fig)
 
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
  for i in range(1, num_points):
27
+ x[i], y[i], z[i] = f(z[i-1], c)
28
+ return (x, y, z[:, 0])
29
 
30
  num_points = st.slider('How many points do you want to generate?', 1000, 100000, 10000)
31
  fractal_type = st.selectbox('Select a fractal type', ('Strange Attractor', 'Julia Set'))
 
47
  else:
48
  real_part = st.slider('Real part of c', -2.0, 2.0, 0.4)
49
  imag_part = st.slider('Imaginary part of c', -2.0, 2.0, 0.1)
50
+ c = (real_part, imag_part)
51
  x, y, z = generate_julia_set(num_points, c)
52
  fig = plt.figure()
53
  ax = fig.add_subplot(111, projection='3d')
54
  ax.plot(x, y, z, linewidth=1)
55
  ax.set_title('Julia Set Fractal')
56
  ax.set_xlabel('X')