yashm commited on
Commit
9d8b7f7
Β·
verified Β·
1 Parent(s): eed2382

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -19
app.py CHANGED
@@ -3,6 +3,7 @@ import matplotlib.pyplot as plt
3
  import numpy as np
4
 
5
  def draw_circle(ax, center, radius, color='black', fill=False, lw=1.5):
 
6
  circle = plt.Circle(
7
  center,
8
  radius,
@@ -15,9 +16,11 @@ def draw_circle(ax, center, radius, color='black', fill=False, lw=1.5):
15
  ax.add_artist(circle)
16
 
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)
@@ -27,40 +30,36 @@ def setup_plot(xlim=(-2, 2), ylim=(-2, 2), aspect='equal'):
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)
@@ -74,37 +73,34 @@ def main():
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)
@@ -116,6 +112,7 @@ def main():
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,
@@ -135,4 +132,4 @@ def main():
135
  """)
136
 
137
  if __name__ == "__main__":
138
- main()
 
3
  import numpy as np
4
 
5
  def draw_circle(ax, center, radius, color='black', fill=False, lw=1.5):
6
+ # Create a circle on the plot
7
  circle = plt.Circle(
8
  center,
9
  radius,
 
16
  ax.add_artist(circle)
17
 
18
  def draw_line(ax, start, end, color='black', lw=1.5):
19
+ # Draw a line between two points
20
  ax.plot([start[0], end[0]], [start[1], end[1]], color=color, lw=lw)
21
 
22
  def setup_plot(xlim=(-2, 2), ylim=(-2, 2), aspect='equal'):
23
+ # Set up the plotting area
24
  fig, ax = plt.subplots(figsize=(8, 8))
25
  ax.set_xlim(xlim)
26
  ax.set_ylim(ylim)
 
30
 
31
  def draw_shree_yantra(ax, radius=1, sides=12, line_skips=None, circle_fill=False,
32
  line_color='black', circle_color='black', layers=2):
33
+ # The heart of the Yantra - where the magic happens
34
  if line_skips is None:
35
  line_skips = [2, 5, 7, 10]
36
 
37
+ # Outer circles - the cosmic spheres
38
  outer_circles = [radius * (i+1) / layers for i in range(layers)]
39
  for r in outer_circles:
40
  draw_circle(ax, (0, 0), r, color=circle_color, fill=circle_fill, lw=2)
41
 
42
+ # Polygons and connecting lines - the web of existence
43
  for layer in range(1, layers + 1):
44
  current_radius = radius * layer / layers
 
45
  points = [np.array([np.cos(theta), np.sin(theta)]) for theta in np.linspace(0, 2*np.pi, sides, endpoint=False)]
46
  scaled_points = [p * current_radius for p in points]
47
  polygon = plt.Polygon(scaled_points, closed=True, fill=False, edgecolor=circle_color, lw=2)
48
  ax.add_artist(polygon)
49
 
50
+ # Connecting lines - the threads of interconnectedness
51
  for i, p1 in enumerate(scaled_points):
52
  for skip in line_skips:
53
  j = (i + skip) % sides
54
  p2 = scaled_points[j]
 
55
  if i < j:
56
  draw_line(ax, p1, p2, color=line_color, lw=1.5)
57
 
58
+ # Central circle - the bindu, the source of all creation
59
  draw_circle(ax, (0, 0), radius / layers, color=circle_color, fill=False, lw=2)
60
 
61
  def enforce_symmetry(selected_skips, sides):
62
+ # Ensure balance in the universe (and our Yantra)
 
 
 
63
  symmetric_skips = set()
64
  for skip in selected_skips:
65
  symmetric_skips.add(skip)
 
73
 
74
  st.sidebar.header("πŸ”§ Customize Your Shree Yantra")
75
 
76
+ # Let the user shape their own cosmic diagram
77
  radius = st.sidebar.slider("πŸ”΅ Outer Circle Radius", 0.5, 3.0, 1.5, 0.1)
78
  sides = st.sidebar.slider("πŸ”Ί Number of Sides (Polygon)", 6, 20, 12, 1)
79
  layers = st.sidebar.slider("πŸ“š Number of Layers", 1, 5, 2, 1)
80
 
81
+ # The sacred skips
82
  predefined_skips = [2, 5, 7, 10]
83
 
 
84
  max_skip = sides // 2
85
  available_skips = list(range(1, max_skip + 1))
86
 
 
87
  default_skips = [skip for skip in predefined_skips if skip in available_skips]
88
  if not default_skips:
89
  default_skips = [2] if 2 in available_skips else [1]
90
 
91
+ # Let the user choose their path
92
  selected_skips = st.sidebar.multiselect(
93
  "πŸ”€ Line Skips",
94
  options=available_skips,
95
  default=default_skips
96
  )
97
 
98
+ # Balance in all things
99
  symmetric_skips = enforce_symmetry(selected_skips, sides)
100
 
 
101
  st.sidebar.write("**πŸ”„ Symmetric Skips Applied:**", symmetric_skips)
102
 
103
+ # Colors of creation
104
  line_color = st.sidebar.color_picker("✏️ Line Color", "#000000")
105
  circle_color = st.sidebar.color_picker("πŸ–ŒοΈ Circle & Polygon Color", "#000000")
106
  circle_fill = st.sidebar.checkbox("🎨 Fill Outer Circles", value=False)
 
112
  if not symmetric_skips:
113
  st.warning("⚠️ Please select at least one line skip to draw connecting lines.")
114
  else:
115
+ # Create the Yantra
116
  draw_shree_yantra(
117
  ax,
118
  radius=radius,
 
132
  """)
133
 
134
  if __name__ == "__main__":
135
+ main()