File size: 1,936 Bytes
a31a033
 
ce4c136
a31a033
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce4c136
a31a033
 
 
 
 
ce4c136
a31a033
 
ce4c136
a31a033
 
 
 
 
 
 
 
 
ce4c136
 
 
b406d52
ce4c136
 
 
 
 
a31a033
ce4c136
 
 
 
 
 
b406d52
ce4c136
 
 
 
b406d52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt

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 (x, y, z)

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)
    z[0] = 1
    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 (x, y, z)

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)
    x, y, z = generate_strange_attractor(num_points, a, b, c, d)
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.plot(x, y, z, linewidth=1)
    ax.set_title('Strange Attractor Fractal')
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    st.pyplot(fig)
else:
    real_part = st.slider('Real part of c', -2.0, 2.0, 0.4)
    imag_part = st.slider('Imaginary part of c', -2.0, 2.0, 0.1)
    c = complex(real_part, imag_part)
    x, y, z = generate_julia_set(num_points, c)
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.plot(x, y, z, linewidth=1)
    ax.set_title('Julia Set Fractal')
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    st.pyplot(fig)