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()