File size: 2,940 Bytes
a31a033
 
ce4c136
a31a033
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce4c136
a31a033
bdcd960
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a31a033
 
bdcd960
a31a033
 
 
 
 
 
ce4c136
 
 
b406d52
ce4c136
 
 
 
 
bdcd960
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce4c136
 
b406d52
bdcd960
ce4c136
bdcd960
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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_fractal_1(num_points, a, b, c, d):
    x, y, z = 0.0, 0.0, 0.0
    points = []
    for i in range(num_points):
        x_dot = np.sin(a * y) - np.sin(b * x)
        y_dot = np.sin(c * x) - np.sin(d * y)
        z_dot = 0.2
        x += x_dot
        y += y_dot
        z += z_dot
        points.append((x, y, z))
    x, y, z = zip(*points)
    return (x, y, z)

def generate_fractal_2(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.2 * x_dot
        y += 0.2 * y_dot
        z += 0.2 * z_dot
        points.append((x, y, z))
    x, y, z = zip(*points)
    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', 'Fractal 1', 'Fractal 2'))

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)

if fractal_type == 'Fractal 1':
    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_fractal_1(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('Fractal 1')
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    st.pyplot(fig)

if fractal_type == 'Fractal 2':
    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_fractal_2(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('Fractal 2')
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    st.pyplot(fig)