File size: 4,744 Bytes
da4ce7a 1a6138e ce9812c 1a6138e 9d8b7f7 c684154 1a6138e ce9812c 1a6138e 9d8b7f7 1a6138e da4ce7a b46e6c5 9d8b7f7 b46e6c5 1a6138e da4ce7a b46e6c5 9d8b7f7 c684154 9d8b7f7 b46e6c5 9d8b7f7 b46e6c5 9d8b7f7 b46e6c5 9d8b7f7 b46e6c5 9d8b7f7 b46e6c5 1a6138e eed2382 1a6138e b46e6c5 1a6138e 9d8b7f7 b46e6c5 c684154 9d8b7f7 c684154 b46e6c5 c684154 9d8b7f7 b46e6c5 c684154 9d8b7f7 b46e6c5 9d8b7f7 b46e6c5 1a6138e eed2382 1a6138e b46e6c5 1a6138e 9d8b7f7 c684154 b46e6c5 c684154 b46e6c5 c684154 1a6138e b46e6c5 eed2382 b46e6c5 1a6138e 9d8b7f7 | 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 | import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
def draw_circle(ax, center, radius, color='black', fill=False, lw=1.5):
# Create a circle on the plot
circle = plt.Circle(
center,
radius,
clip_on=False,
edgecolor=color,
facecolor='none' if not fill else color,
lw=lw,
fill=fill
)
ax.add_artist(circle)
def draw_line(ax, start, end, color='black', lw=1.5):
# Draw a line between two points
ax.plot([start[0], end[0]], [start[1], end[1]], color=color, lw=lw)
def setup_plot(xlim=(-2, 2), ylim=(-2, 2), aspect='equal'):
# Set up the plotting area
fig, ax = plt.subplots(figsize=(8, 8))
ax.set_xlim(xlim)
ax.set_ylim(ylim)
ax.set_aspect(aspect)
ax.axis('off')
return fig, ax
def draw_shree_yantra(ax, radius=1, sides=12, line_skips=None, circle_fill=False,
line_color='black', circle_color='black', layers=2):
# The heart of the Yantra - where the magic happens
if line_skips is None:
line_skips = [2, 5, 7, 10]
# Outer circles - the cosmic spheres
outer_circles = [radius * (i+1) / layers for i in range(layers)]
for r in outer_circles:
draw_circle(ax, (0, 0), r, color=circle_color, fill=circle_fill, lw=2)
# Polygons and connecting lines - the web of existence
for layer in range(1, layers + 1):
current_radius = radius * layer / layers
points = [np.array([np.cos(theta), np.sin(theta)]) for theta in np.linspace(0, 2*np.pi, sides, endpoint=False)]
scaled_points = [p * current_radius for p in points]
polygon = plt.Polygon(scaled_points, closed=True, fill=False, edgecolor=circle_color, lw=2)
ax.add_artist(polygon)
# Connecting lines - the threads of interconnectedness
for i, p1 in enumerate(scaled_points):
for skip in line_skips:
j = (i + skip) % sides
p2 = scaled_points[j]
if i < j:
draw_line(ax, p1, p2, color=line_color, lw=1.5)
# Central circle - the bindu, the source of all creation
draw_circle(ax, (0, 0), radius / layers, color=circle_color, fill=False, lw=2)
def enforce_symmetry(selected_skips, sides):
# Ensure balance in the universe (and our Yantra)
symmetric_skips = set()
for skip in selected_skips:
symmetric_skips.add(skip)
complement = sides - skip
if complement != skip:
symmetric_skips.add(complement)
return sorted(symmetric_skips)
def main():
st.title("ποΈ Yantra Diagram Generator")
st.sidebar.header("π§ Customize Your Shree Yantra")
# Let the user shape their own cosmic diagram
radius = st.sidebar.slider("π΅ Outer Circle Radius", 0.5, 3.0, 1.5, 0.1)
sides = st.sidebar.slider("πΊ Number of Sides (Polygon)", 6, 20, 12, 1)
layers = st.sidebar.slider("π Number of Layers", 1, 5, 2, 1)
# The sacred skips
predefined_skips = [2, 5, 7, 10]
max_skip = sides // 2
available_skips = list(range(1, max_skip + 1))
default_skips = [skip for skip in predefined_skips if skip in available_skips]
if not default_skips:
default_skips = [2] if 2 in available_skips else [1]
# Let the user choose their path
selected_skips = st.sidebar.multiselect(
"π Line Skips",
options=available_skips,
default=default_skips
)
# Balance in all things
symmetric_skips = enforce_symmetry(selected_skips, sides)
st.sidebar.write("**π Symmetric Skips Applied:**", symmetric_skips)
# Colors of creation
line_color = st.sidebar.color_picker("βοΈ Line Color", "#000000")
circle_color = st.sidebar.color_picker("ποΈ Circle & Polygon Color", "#000000")
circle_fill = st.sidebar.checkbox("π¨ Fill Outer Circles", value=False)
st.write("### ποΈ Yantra Diagram")
fig, ax = setup_plot()
if not symmetric_skips:
st.warning("β οΈ Please select at least one line skip to draw connecting lines.")
else:
# Create the Yantra
draw_shree_yantra(
ax,
radius=radius,
sides=sides,
line_skips=symmetric_skips,
circle_fill=circle_fill,
line_color=line_color,
circle_color=circle_color,
layers=layers
)
st.pyplot(fig)
st.markdown("""
---
**βΉοΈ About Shree Yantra**: The Yantra is a sacred geometrical diagram used in Hinduism for meditation and worship. It consists of nine interlocking triangles forming 43 smaller triangles, symbolizing the union of the divine and the material world.
""")
if __name__ == "__main__":
main() |