Update app.py
Browse files
app.py
CHANGED
|
@@ -17,83 +17,122 @@ def draw_circle(ax, center, radius, color='black', fill=False, lw=1.5):
|
|
| 17 |
def draw_line(ax, start, end, color='black', lw=1.5):
|
| 18 |
ax.plot([start[0], end[0]], [start[1], end[1]], color=color, lw=lw)
|
| 19 |
|
| 20 |
-
def setup_plot(xlim=(-
|
| 21 |
-
fig, ax = plt.subplots(figsize=(
|
| 22 |
ax.set_xlim(xlim)
|
| 23 |
ax.set_ylim(ylim)
|
| 24 |
ax.set_aspect(aspect)
|
| 25 |
ax.axis('off')
|
| 26 |
return fig, ax
|
| 27 |
|
| 28 |
-
def draw_shree_yantra(ax, radius=1, sides=12, line_skips=None, circle_fill=False,
|
|
|
|
| 29 |
if line_skips is None:
|
| 30 |
line_skips = [2, 5, 7, 10]
|
| 31 |
|
| 32 |
-
# Step 1: Draw outer
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def main():
|
| 49 |
-
st.title("Shree Yantra Diagram Generator")
|
| 50 |
|
| 51 |
-
st.sidebar.header("Customize Your Shree Yantra")
|
| 52 |
|
| 53 |
# Sidebar controls
|
| 54 |
-
radius = st.sidebar.slider("Outer Circle Radius", 0.5,
|
| 55 |
-
sides = st.sidebar.slider("Number of Sides (Polygon)", 6, 20, 12, 1)
|
|
|
|
| 56 |
|
| 57 |
# Define default skips
|
| 58 |
predefined_skips = [2, 5, 7, 10]
|
| 59 |
|
| 60 |
-
# Generate available
|
| 61 |
max_skip = sides // 2
|
| 62 |
available_skips = list(range(1, max_skip + 1))
|
| 63 |
|
| 64 |
# Adjust default skips to be within available options
|
| 65 |
default_skips = [skip for skip in predefined_skips if skip in available_skips]
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Provide user flexibility to select skips
|
| 68 |
-
|
| 69 |
-
"Line Skips",
|
| 70 |
options=available_skips,
|
| 71 |
default=default_skips
|
| 72 |
)
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
# Additional sidebar controls
|
| 75 |
-
line_color = st.sidebar.color_picker("Line Color", "#000000")
|
| 76 |
-
circle_color = st.sidebar.color_picker("Circle & Polygon Color", "#000000")
|
| 77 |
-
circle_fill = st.sidebar.checkbox("Fill Outer
|
| 78 |
|
| 79 |
-
st.write("### Shree Yantra Diagram")
|
| 80 |
|
| 81 |
fig, ax = setup_plot()
|
| 82 |
|
| 83 |
-
if not
|
| 84 |
-
st.warning("Please select at least one line skip to draw connecting lines.")
|
| 85 |
else:
|
| 86 |
draw_shree_yantra(
|
| 87 |
ax,
|
| 88 |
radius=radius,
|
| 89 |
sides=sides,
|
| 90 |
-
line_skips=
|
| 91 |
circle_fill=circle_fill,
|
| 92 |
line_color=line_color,
|
| 93 |
-
circle_color=circle_color
|
|
|
|
| 94 |
)
|
| 95 |
|
| 96 |
st.pyplot(fig)
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
if __name__ == "__main__":
|
| 99 |
main()
|
|
|
|
| 17 |
def draw_line(ax, start, end, color='black', lw=1.5):
|
| 18 |
ax.plot([start[0], end[0]], [start[1], end[1]], color=color, lw=lw)
|
| 19 |
|
| 20 |
+
def setup_plot(xlim=(-2, 2), ylim=(-2, 2), aspect='equal'):
|
| 21 |
+
fig, ax = plt.subplots(figsize=(8, 8))
|
| 22 |
ax.set_xlim(xlim)
|
| 23 |
ax.set_ylim(ylim)
|
| 24 |
ax.set_aspect(aspect)
|
| 25 |
ax.axis('off')
|
| 26 |
return fig, ax
|
| 27 |
|
| 28 |
+
def draw_shree_yantra(ax, radius=1, sides=12, line_skips=None, circle_fill=False,
|
| 29 |
+
line_color='black', circle_color='black', layers=2):
|
| 30 |
if line_skips is None:
|
| 31 |
line_skips = [2, 5, 7, 10]
|
| 32 |
|
| 33 |
+
# Step 1: Draw outer circles
|
| 34 |
+
outer_circles = [radius * (i+1) / layers for i in range(layers)]
|
| 35 |
+
for r in outer_circles:
|
| 36 |
+
draw_circle(ax, (0, 0), r, color=circle_color, fill=circle_fill, lw=2)
|
| 37 |
+
|
| 38 |
+
# Step 2: Draw polygons and connecting lines for each layer
|
| 39 |
+
for layer in range(1, layers + 1):
|
| 40 |
+
current_radius = radius * layer / layers
|
| 41 |
+
# Draw polygon
|
| 42 |
+
points = [np.array([np.cos(theta), np.sin(theta)]) for theta in np.linspace(0, 2*np.pi, sides, endpoint=False)]
|
| 43 |
+
scaled_points = [p * current_radius for p in points]
|
| 44 |
+
polygon = plt.Polygon(scaled_points, closed=True, fill=False, edgecolor=circle_color, lw=2)
|
| 45 |
+
ax.add_artist(polygon)
|
| 46 |
+
|
| 47 |
+
# Draw symmetric connecting lines
|
| 48 |
+
for i, p1 in enumerate(scaled_points):
|
| 49 |
+
for skip in line_skips:
|
| 50 |
+
j = (i + skip) % sides
|
| 51 |
+
p2 = scaled_points[j]
|
| 52 |
+
# To ensure symmetry, draw each line only once
|
| 53 |
+
if i < j:
|
| 54 |
+
draw_line(ax, p1, p2, color=line_color, lw=1.5)
|
| 55 |
+
|
| 56 |
+
# Step 3: Draw central circle
|
| 57 |
+
draw_circle(ax, (0, 0), radius / layers, color=circle_color, fill=False, lw=2)
|
| 58 |
+
|
| 59 |
+
def enforce_symmetry(selected_skips, sides):
|
| 60 |
+
"""
|
| 61 |
+
Ensure that for every skip, its complementary skip is also selected.
|
| 62 |
+
For example, if skip=2 is selected in a 12-sided polygon, skip=10 (12-2) is also selected.
|
| 63 |
+
"""
|
| 64 |
+
symmetric_skips = set()
|
| 65 |
+
for skip in selected_skips:
|
| 66 |
+
symmetric_skips.add(skip)
|
| 67 |
+
complement = sides - skip
|
| 68 |
+
if complement != skip:
|
| 69 |
+
symmetric_skips.add(complement)
|
| 70 |
+
return sorted(symmetric_skips)
|
| 71 |
|
| 72 |
def main():
|
| 73 |
+
st.title("ποΈ Shree Yantra Diagram Generator")
|
| 74 |
|
| 75 |
+
st.sidebar.header("π§ Customize Your Shree Yantra")
|
| 76 |
|
| 77 |
# Sidebar controls
|
| 78 |
+
radius = st.sidebar.slider("π΅ Outer Circle Radius", 0.5, 3.0, 1.5, 0.1)
|
| 79 |
+
sides = st.sidebar.slider("πΊ Number of Sides (Polygon)", 6, 20, 12, 1)
|
| 80 |
+
layers = st.sidebar.slider("π Number of Layers", 1, 5, 2, 1)
|
| 81 |
|
| 82 |
# Define default skips
|
| 83 |
predefined_skips = [2, 5, 7, 10]
|
| 84 |
|
| 85 |
+
# Generate available skips based on the number of sides
|
| 86 |
max_skip = sides // 2
|
| 87 |
available_skips = list(range(1, max_skip + 1))
|
| 88 |
|
| 89 |
# Adjust default skips to be within available options
|
| 90 |
default_skips = [skip for skip in predefined_skips if skip in available_skips]
|
| 91 |
+
if not default_skips:
|
| 92 |
+
default_skips = [2] if 2 in available_skips else [1]
|
| 93 |
|
| 94 |
# Provide user flexibility to select skips
|
| 95 |
+
selected_skips = st.sidebar.multiselect(
|
| 96 |
+
"π Line Skips",
|
| 97 |
options=available_skips,
|
| 98 |
default=default_skips
|
| 99 |
)
|
| 100 |
|
| 101 |
+
# Enforce symmetry in skips
|
| 102 |
+
symmetric_skips = enforce_symmetry(selected_skips, sides)
|
| 103 |
+
|
| 104 |
+
# Display selected symmetric skips
|
| 105 |
+
st.sidebar.write("**π Symmetric Skips Applied:**", symmetric_skips)
|
| 106 |
+
|
| 107 |
# Additional sidebar controls
|
| 108 |
+
line_color = st.sidebar.color_picker("βοΈ Line Color", "#000000")
|
| 109 |
+
circle_color = st.sidebar.color_picker("ποΈ Circle & Polygon Color", "#000000")
|
| 110 |
+
circle_fill = st.sidebar.checkbox("π¨ Fill Outer Circles", value=False)
|
| 111 |
|
| 112 |
+
st.write("### ποΈ Shree Yantra Diagram")
|
| 113 |
|
| 114 |
fig, ax = setup_plot()
|
| 115 |
|
| 116 |
+
if not symmetric_skips:
|
| 117 |
+
st.warning("β οΈ Please select at least one line skip to draw connecting lines.")
|
| 118 |
else:
|
| 119 |
draw_shree_yantra(
|
| 120 |
ax,
|
| 121 |
radius=radius,
|
| 122 |
sides=sides,
|
| 123 |
+
line_skips=symmetric_skips,
|
| 124 |
circle_fill=circle_fill,
|
| 125 |
line_color=line_color,
|
| 126 |
+
circle_color=circle_color,
|
| 127 |
+
layers=layers
|
| 128 |
)
|
| 129 |
|
| 130 |
st.pyplot(fig)
|
| 131 |
|
| 132 |
+
st.markdown("""
|
| 133 |
+
---
|
| 134 |
+
**βΉοΈ About Shree Yantra**: The Shree 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.
|
| 135 |
+
""")
|
| 136 |
+
|
| 137 |
if __name__ == "__main__":
|
| 138 |
main()
|