eaglelandsonce commited on
Commit
7a50d25
·
verified ·
1 Parent(s): 8bb3175

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -29
app.py CHANGED
@@ -54,42 +54,28 @@ def draw_grid(data, highlight_coords=None):
54
  ax.grid(True)
55
 
56
  # Draw roads
 
57
  for road in data.get('roads', []): # Default to empty list if no roads key
58
  start = road['start']
59
  end = road['end']
60
  color = color_codes.get("road", '#898989') # Default color is gray for roads
61
  ax.plot([start[1], end[1]], [nrows-start[0], nrows-end[0]], color=color, linewidth=2) # Adjust coordinates for matplotlib
 
62
 
63
- # Draw buildings
64
- for building in data['buildings']:
65
- coords = building['coords']
66
- b_type = building['type']
67
- size = building['size']
68
- color = color_codes.get(b_type, '#FFFFFF') # Default color is white if not specified
69
-
70
- if highlight_coords and (coords[0], coords[1]) == tuple(highlight_coords):
71
- highlighted_color = "#FFD700" # Gold for highlighting
72
- ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=highlighted_color, edgecolor='black', linewidth=2))
73
- else:
74
- ax.add_patch(plt.Rectangle((coords[1], nrows-coords[0]-size), size, size, color=color, edgecolor='black', linewidth=1))
75
- ax.text(coords[1]+0.5*size, nrows-coords[0]-0.5*size, b_type, ha='center', va='center', fontsize=8, color='black')
76
-
77
- ax.set_xlabel('Columns')
78
- ax.set_ylabel('Rows')
79
- ax.set_title('Village Layout with Color Coding')
80
- return fig
81
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
- """
84
- def draw_grid(data, highlight_coords=None):
85
- fig, ax = plt.subplots(figsize=(12, 12))
86
- nrows, ncols = data['size']['rows'], data['size']['columns']
87
- ax.set_xlim(0, ncols)
88
- ax.set_ylim(0, nrows)
89
- ax.set_xticks(range(ncols+1))
90
- ax.set_yticks(range(nrows+1))
91
- ax.grid(True)
92
-
93
  for building in data['buildings']:
94
  coords = building['coords']
95
  b_type = building['type']
@@ -108,7 +94,7 @@ def draw_grid(data, highlight_coords=None):
108
  ax.set_title('Village Layout with Color Coding')
109
  return fig
110
 
111
- """
112
 
113
  # Main Streamlit app function
114
  def main():
 
54
  ax.grid(True)
55
 
56
  # Draw roads
57
+ """
58
  for road in data.get('roads', []): # Default to empty list if no roads key
59
  start = road['start']
60
  end = road['end']
61
  color = color_codes.get("road", '#898989') # Default color is gray for roads
62
  ax.plot([start[1], end[1]], [nrows-start[0], nrows-end[0]], color=color, linewidth=2) # Adjust coordinates for matplotlib
63
+ """
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
+ # Draw roads with a specified grey color
67
+ road_color = "#A0A0A0" # Light grey; change to "#505050" for dark grey
68
+ for road in data.get('roads', []): # Check for roads in the data
69
+ start, end = road['start'], road['end']
70
+ # Determine if the road is vertical or horizontal based on start and end coordinates
71
+ if start[0] == end[0]: # Vertical road
72
+ for y in range(min(start[1], end[1]), max(start[1], end[1]) + 1):
73
+ ax.add_patch(plt.Rectangle((start[0], nrows-y-1), 1, 1, color=road_color))
74
+ else: # Horizontal road
75
+ for x in range(min(start[0], end[0]), max(start[0], end[0]) + 1):
76
+ ax.add_patch(plt.Rectangle((x, nrows-start[1]-1), 1, 1, color=road_color))
77
 
78
+ # Draw buildings
 
 
 
 
 
 
 
 
 
79
  for building in data['buildings']:
80
  coords = building['coords']
81
  b_type = building['type']
 
94
  ax.set_title('Village Layout with Color Coding')
95
  return fig
96
 
97
+
98
 
99
  # Main Streamlit app function
100
  def main():