Spaces:
Sleeping
Sleeping
import matplotlib.pyplot as plt | |
import numpy as np | |
import streamlit as st | |
def fractal(x, y): | |
# Fractal equation | |
z = complex(x, y) | |
c = complex(-0.7, 0.27) | |
iterations = 100 | |
for i in range(iterations): | |
z = z * z + c | |
if abs(z) > 2: | |
return i | |
return iterations | |
# Generate the fractal data | |
xmin, xmax, ymin, ymax = -2.0, 2.0, -2.0, 2.0 | |
n = 500 # Number of points along each axis | |
x = np.linspace(xmin, xmax, n) | |
y = np.linspace(ymin, ymax, n) | |
X, Y = np.meshgrid(x, y) | |
Z = np.zeros_like(X) | |
for i in range(n): | |
for j in range(n): | |
Z[i, j] = fractal(X[i, j], Y[i, j]) | |
# Display the fractal using matplotlib | |
plt.imshow(Z, cmap='hot', extent=[xmin, xmax, ymin, ymax], origin='lower') | |
plt.colorbar(label='Iterations') | |
plt.title("Fractal Visualization") | |
plt.xlabel("Real") | |
plt.ylabel("Imaginary") | |
st.pyplot(plt) |