|
import streamlit as st |
|
import matplotlib.pyplot as plt |
|
import numpy as np |
|
import matplotlib.colors as mcolors |
|
|
|
|
|
golden_ratio = (1 + np.sqrt(5)) / 2 |
|
color_wheel = plt.get_cmap('hsv') |
|
|
|
def is_prime(n): |
|
"""Check if a number is prime.""" |
|
if n <= 1: |
|
return False |
|
for i in range(2, int(n**0.5) + 1): |
|
if n % i == 0: |
|
return False |
|
return True |
|
|
|
def fib_sequence(n): |
|
"""Generate Fibonacci sequence up to n.""" |
|
fib_seq = [0, 1] |
|
while fib_seq[-1] + fib_seq[-2] <= n: |
|
fib_seq.append(fib_seq[-1] + fib_seq[-2]) |
|
return fib_seq[2:] |
|
|
|
def adjust_color_brightness(color, factor): |
|
"""Adjust the brightness of a color.""" |
|
return tuple(np.array(mcolors.to_rgb(color)) * factor) |
|
|
|
def generate_colored_circle_template(num_circles): |
|
"""Improved use of color and symmetry in circle generation.""" |
|
fig, ax = plt.subplots(figsize=(6, 6)) |
|
ax.set_xlim(0, 1) |
|
ax.set_ylim(0, 1) |
|
ax.axis('off') |
|
|
|
for i in range(num_circles): |
|
radius = np.random.uniform(0.05, 0.1) |
|
angle = 2 * np.pi * i / num_circles |
|
distance = np.sqrt(np.random.uniform(0.1, 0.9)) |
|
x = 0.5 + distance * np.cos(angle) |
|
y = 0.5 + distance * np.sin(angle) |
|
color = color_wheel(i / num_circles) |
|
alpha = 0.6 + 0.4 * (1 - distance) |
|
circle = plt.Circle((x, y), radius, color=color, alpha=alpha) |
|
ax.add_artist(circle) |
|
return fig |
|
|
|
def generate_symmetrical_circle_layout(num_layers): |
|
"""Generate a more symmetrical circle layout.""" |
|
fig, ax = plt.subplots(figsize=(6, 6)) |
|
ax.set_aspect('equal') |
|
ax.axis('off') |
|
|
|
max_radius = 0.1 + 0.15 * (num_layers - 1) |
|
center = (0.5, 0.5) |
|
|
|
for layer in range(num_layers): |
|
radius = 0.05 + layer * 0.1 |
|
num_circles = layer * 6 if layer > 0 else 1 |
|
for i in range(num_circles): |
|
angle = 2 * np.pi * i / num_circles |
|
x = center[0] + radius * np.cos(angle) |
|
y = center[1] + radius * np.sin(angle) |
|
color = color_wheel(i / num_circles) |
|
circle = plt.Circle((x, y), max_radius / num_layers, color=color, alpha=0.5 + 0.5 * (1 - layer / num_layers)) |
|
ax.add_artist(circle) |
|
return fig |
|
|
|
def generate_fibonacci_spiral_layout(num_points): |
|
"""Generate layout based on Fibonacci spiral.""" |
|
fig, ax = plt.subplots(figsize=(6, 6)) |
|
ax.axis('off') |
|
radius = 0.05 |
|
for i in range(num_points): |
|
angle = i * 2 * np.pi / golden_ratio |
|
distance = np.sqrt(i) * radius |
|
x = 0.5 + distance * np.cos(angle) |
|
y = 0.5 + distance * np.sin(angle) |
|
color = color_wheel(i / num_points) |
|
circle = plt.Circle((x, y), radius, color=color, fill=True, alpha=0.8) |
|
ax.add_artist(circle) |
|
ax.set_aspect('equal') |
|
return fig |
|
|
|
def generate_prime_number_spiral(num_points): |
|
"""Generate spiral layout highlighting prime numbers.""" |
|
fig, ax = plt.subplots(figsize=(6, 6)) |
|
ax.axis('off') |
|
radius = 0.05 |
|
for i in range(1, num_points + 1): |
|
if is_prime(i): |
|
angle = i * 2 * np.pi / golden_ratio |
|
distance = np.sqrt(i) * radius |
|
x = 0.5 + distance * np.cos(angle) |
|
y = 0.5 + distance * np.sin(angle) |
|
color = color_wheel(i / num_points) |
|
circle = plt.Circle((x, y), radius, color=color, fill=True, alpha=0.8) |
|
ax.add_artist(circle) |
|
ax.set_aspect('equal') |
|
return fig |
|
|
|
def emoji_dynamics_and_number_theory_simulation(size): |
|
"""Simulate emoji dynamics based on number theory.""" |
|
fib_seq = fib_sequence(size**2) |
|
grid = [] |
|
|
|
for i in range(1, size**2 + 1): |
|
if i in fib_seq: |
|
grid.append("π") |
|
elif is_prime(i): |
|
grid.append("π") |
|
else: |
|
grid.append("βͺ") |
|
|
|
if i % size == 0: |
|
grid.append("\n") |
|
|
|
return "".join(grid) |
|
|
|
|
|
st.title("Circle Packings and Number Theory Visualizations") |
|
|
|
mode = st.radio( |
|
"Choose a visualization mode:", |
|
("Random Circle Packings", "Symmetrical Circle Layouts", "Fibonacci Spiral Layout", "Prime Number Spiral", "Emoji Dynamics and Number Theory Simulation") |
|
) |
|
|
|
if mode == "Random Circle Packings": |
|
num_circles = st.slider("Number of Circles", 5, 50, 10) |
|
fig = generate_colored_circle_template(num_circles) |
|
elif mode == "Symmetrical Circle Layouts": |
|
num_layers = st.slider("Number of Symmetrical Layers", 1, 5, 3) |
|
fig = generate_symmetrical_circle_layout(num_layers) |
|
elif mode == "Fibonacci Spiral Layout": |
|
num_points = st.slider("Number of Points", 10, 100, 30) |
|
fig = generate_fibonacci_spiral_layout(num_points) |
|
elif mode == "Prime Number Spiral": |
|
num_points = st.slider("Number of Points", 10, 1000, 200) |
|
fig = generate_prime_number_spiral(num_points) |
|
elif mode == "Emoji Dynamics and Number Theory Simulation": |
|
size = st.slider("Grid Size", 5, 20, 10) |
|
simulation = emoji_dynamics_and_number_theory_simulation(size) |
|
st.text(simulation) |
|
else: |
|
st.text("Select a visualization mode to display.") |
|
|
|
if 'fig' in locals(): |
|
st.pyplot(fig) |
|
|