File size: 5,469 Bytes
bdf68d5 68599bb bdf68d5 68599bb 7791160 5a34697 7791160 68599bb 5a34697 68599bb bdf68d5 5a34697 bdf68d5 68599bb 5a34697 bdf68d5 5a34697 bdf68d5 5a34697 bdf68d5 5a34697 bdf68d5 5a34697 bdf68d5 7a37a91 5a34697 7a37a91 7791160 7a37a91 5a34697 7a37a91 5a34697 7a37a91 5a34697 7a37a91 68599bb 5a34697 68599bb bdf68d5 7a37a91 68599bb 7a37a91 bdf68d5 7a37a91 68599bb 7a37a91 68599bb |
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as mcolors
# Global constant for golden ratio
golden_ratio = (1 + np.sqrt(5)) / 2
color_wheel = plt.get_cmap('hsv') # Use the HSV color wheel for harmonious colors
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:] # Exclude first two numbers for this use case
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) # More transparent further out
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) # Adjust so outer circles don't overlap the figure boundary
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 # Increase circles in outer layers
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("π") # Fibonacci positions
elif is_prime(i):
grid.append("π") # Prime positions
else:
grid.append("βͺ") # Other positions
if i % size == 0:
grid.append("\n") # Newline at the end of each row
return "".join(grid)
# Streamlit UI setup
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)
|