Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,36 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib.pyplot as plt
|
2 |
+
import numpy as np
|
3 |
import streamlit as st
|
4 |
|
5 |
+
def fractal(x, y):
|
6 |
+
# Fractal equation
|
7 |
+
z = complex(x, y)
|
8 |
+
c = complex(-0.7, 0.27)
|
9 |
+
iterations = 100
|
10 |
+
|
11 |
+
for i in range(iterations):
|
12 |
+
z = z * z + c
|
13 |
+
if abs(z) > 2:
|
14 |
+
return i
|
15 |
+
|
16 |
+
return iterations
|
17 |
+
|
18 |
+
# Generate the fractal data
|
19 |
+
xmin, xmax, ymin, ymax = -2.0, 2.0, -2.0, 2.0
|
20 |
+
n = 500 # Number of points along each axis
|
21 |
+
x = np.linspace(xmin, xmax, n)
|
22 |
+
y = np.linspace(ymin, ymax, n)
|
23 |
+
X, Y = np.meshgrid(x, y)
|
24 |
+
Z = np.zeros_like(X)
|
25 |
+
|
26 |
+
for i in range(n):
|
27 |
+
for j in range(n):
|
28 |
+
Z[i, j] = fractal(X[i, j], Y[i, j])
|
29 |
+
|
30 |
+
# Display the fractal using matplotlib
|
31 |
+
plt.imshow(Z, cmap='hot', extent=[xmin, xmax, ymin, ymax], origin='lower')
|
32 |
+
plt.colorbar(label='Iterations')
|
33 |
+
plt.title("Fractal Visualization")
|
34 |
+
plt.xlabel("Real")
|
35 |
+
plt.ylabel("Imaginary")
|
36 |
+
st.pyplot(plt)
|