mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 13:23:00 +00:00
refactor: Position outs vertically beside bases in live MLB display
This commit is contained in:
@@ -541,83 +541,80 @@ class MLBLiveManager(BaseMLBManager):
|
|||||||
inning_y = 2 # Position near top center
|
inning_y = 2 # Position near top center
|
||||||
draw.text((inning_x, inning_y), inning_text, fill=(255, 255, 255), font=self.display_manager.font)
|
draw.text((inning_x, inning_y), inning_text, fill=(255, 255, 255), font=self.display_manager.font)
|
||||||
|
|
||||||
# --- NEW BASES AND COUNT DRAWING ---
|
# --- REVISED BASES AND OUTS DRAWING ---
|
||||||
bases_occupied = game_data['bases_occupied'] # [1st, 2nd, 3rd]
|
bases_occupied = game_data['bases_occupied'] # [1st, 2nd, 3rd]
|
||||||
balls = game_data['balls']
|
outs = game_data.get('outs', 0)
|
||||||
strikes = game_data['strikes']
|
inning_half = game_data['inning_half']
|
||||||
|
|
||||||
# Define geometry
|
# Define geometry
|
||||||
diamond_size = 7 # Increase size of the base diamonds
|
base_diamond_size = 7
|
||||||
circle_diameter = 3 # Diameter of the count circles
|
out_circle_diameter = 3
|
||||||
vertical_spacing = 1 # Space between bases row and count row
|
out_vertical_spacing = 1 # Space between out circles
|
||||||
horizontal_spacing = 2 # Increase space between elements
|
spacing_between_bases_outs = 3 # Horizontal space between base cluster and out column
|
||||||
|
base_vert_spacing = 1 # Internal vertical space in base cluster
|
||||||
|
base_horiz_spacing = 1 # Internal horizontal space in base cluster
|
||||||
|
|
||||||
# Calculate total dimensions
|
# Calculate cluster dimensions
|
||||||
base_cluster_height = diamond_size + vertical_spacing + circle_diameter
|
base_cluster_height = base_diamond_size + base_vert_spacing + base_diamond_size
|
||||||
# Width is roughly max(width_of_2nd_base_diamond, width_of_1st+3rd+spacing, width_of_3_circles+spacing)
|
base_cluster_width = base_diamond_size + base_horiz_spacing + base_diamond_size
|
||||||
# For simplicity, approximate using 3 circles width as it's likely widest
|
out_cluster_height = 3 * out_circle_diameter + 2 * out_vertical_spacing
|
||||||
count_cluster_width = 3 * circle_diameter + 2 * horizontal_spacing
|
out_cluster_width = out_circle_diameter
|
||||||
base_row_width = 2 * diamond_size + horizontal_spacing # Width for 1st and 3rd base
|
total_width = base_cluster_width + spacing_between_bases_outs + out_cluster_width
|
||||||
cluster_width = max(count_cluster_width, base_row_width, diamond_size)
|
|
||||||
|
# Calculate overall start positions
|
||||||
|
overall_start_x = (width - total_width) // 2
|
||||||
|
overall_start_y = inning_bbox[3] + 3 # Start below inning text
|
||||||
|
|
||||||
|
# Determine relative positions based on inning half
|
||||||
|
if inning_half == 'top': # Away batting, outs on left
|
||||||
|
outs_column_x = overall_start_x
|
||||||
|
bases_origin_x = overall_start_x + out_cluster_width + spacing_between_bases_outs
|
||||||
|
else: # Home batting, outs on right
|
||||||
|
bases_origin_x = overall_start_x
|
||||||
|
outs_column_x = overall_start_x + base_cluster_width + spacing_between_bases_outs
|
||||||
|
|
||||||
|
# Calculate vertical alignment offset for outs column (center align with bases cluster)
|
||||||
|
outs_column_start_y = overall_start_y + (base_cluster_height // 2) - (out_cluster_height // 2)
|
||||||
|
|
||||||
# Calculate center position for the cluster
|
|
||||||
cluster_start_x = (width - cluster_width) // 2
|
|
||||||
cluster_start_y = inning_bbox[3] + 3 # Start 3 pixels below inning text
|
|
||||||
|
|
||||||
# --- Draw Bases (Diamonds) ---
|
# --- Draw Bases (Diamonds) ---
|
||||||
base_color_occupied = (255, 255, 255)
|
base_color_occupied = (255, 255, 255)
|
||||||
base_color_empty = (255, 255, 255) # Outline color
|
base_color_empty = (255, 255, 255) # Outline color
|
||||||
|
h_d = base_diamond_size // 2
|
||||||
|
|
||||||
# Calculate diamond points relative to their center
|
# 2nd Base (Top center relative to bases_origin_x)
|
||||||
h_d = diamond_size // 2 # half diamond size
|
c2x = bases_origin_x + base_cluster_width // 2
|
||||||
|
c2y = overall_start_y + h_d
|
||||||
|
poly2 = [(c2x, overall_start_y), (c2x + h_d, c2y), (c2x, c2y + h_d), (c2x - h_d, c2y)]
|
||||||
|
if bases_occupied[1]: draw.polygon(poly2, fill=base_color_occupied)
|
||||||
|
else: draw.polygon(poly2, outline=base_color_empty)
|
||||||
|
|
||||||
# 2nd Base (Top center of cluster)
|
base_bottom_y = c2y + h_d # Bottom Y of 2nd base diamond
|
||||||
c2x = cluster_start_x + cluster_width // 2
|
|
||||||
c2y = cluster_start_y + h_d
|
|
||||||
poly2 = [(c2x, cluster_start_y), (c2x + h_d, c2y), (c2x, c2y + h_d), (c2x - h_d, c2y)]
|
|
||||||
if bases_occupied[1]: # Index 1 is 2nd base
|
|
||||||
draw.polygon(poly2, fill=base_color_occupied)
|
|
||||||
else:
|
|
||||||
draw.polygon(poly2, outline=base_color_empty)
|
|
||||||
|
|
||||||
base_bottom_y = c2y + h_d
|
# 1st Base (Bottom left relative to bases_origin_x)
|
||||||
|
c1x = bases_origin_x + h_d
|
||||||
# 1st Base (Bottom left of cluster)
|
c1y = base_bottom_y + base_vert_spacing + h_d
|
||||||
c1x = cluster_start_x + h_d
|
poly1 = [(c1x, base_bottom_y + base_vert_spacing), (c1x + h_d, c1y), (c1x, c1y + h_d), (c1x - h_d, c1y)]
|
||||||
c1y = base_bottom_y + vertical_spacing + h_d
|
if bases_occupied[0]: draw.polygon(poly1, fill=base_color_occupied)
|
||||||
poly1 = [(c1x, base_bottom_y + vertical_spacing), (c1x + h_d, c1y), (c1x, c1y + h_d), (c1x - h_d, c1y)]
|
else: draw.polygon(poly1, outline=base_color_empty)
|
||||||
if bases_occupied[0]: # Index 0 is 1st base
|
|
||||||
draw.polygon(poly1, fill=base_color_occupied)
|
|
||||||
else:
|
|
||||||
draw.polygon(poly1, outline=base_color_empty)
|
|
||||||
|
|
||||||
# 3rd Base (Bottom right of cluster)
|
# 3rd Base (Bottom right relative to bases_origin_x)
|
||||||
c3x = cluster_start_x + cluster_width - h_d
|
c3x = bases_origin_x + base_cluster_width - h_d
|
||||||
c3y = base_bottom_y + vertical_spacing + h_d
|
c3y = base_bottom_y + base_vert_spacing + h_d
|
||||||
poly3 = [(c3x, base_bottom_y + vertical_spacing), (c3x + h_d, c3y), (c3x, c3y + h_d), (c3x - h_d, c3y)]
|
poly3 = [(c3x, base_bottom_y + base_vert_spacing), (c3x + h_d, c3y), (c3x, c3y + h_d), (c3x - h_d, c3y)]
|
||||||
if bases_occupied[2]: # Index 2 is 3rd base
|
if bases_occupied[2]: draw.polygon(poly3, fill=base_color_occupied)
|
||||||
draw.polygon(poly3, fill=base_color_occupied)
|
else: draw.polygon(poly3, outline=base_color_empty)
|
||||||
else:
|
|
||||||
draw.polygon(poly3, outline=base_color_empty)
|
|
||||||
|
|
||||||
bases_overall_bottom_y = c1y + h_d # Bottom of the 1st/3rd base diamonds
|
# --- Draw Outs (Vertical Circles) ---
|
||||||
|
circle_color_out = (255, 255, 255)
|
||||||
# --- Draw Outs (Circles) ---
|
circle_color_empty_outline = (100, 100, 100)
|
||||||
outs = game_data.get('outs', 0) # Get outs, default to 0 if missing
|
|
||||||
count_vertical_offset = 3 # Space below bases
|
|
||||||
count_start_y = bases_overall_bottom_y + count_vertical_offset
|
|
||||||
count_start_x = cluster_start_x + (cluster_width - count_cluster_width) // 2
|
|
||||||
circle_color_out = (255, 255, 255) # White filled circle for out
|
|
||||||
circle_color_empty_outline = (100, 100, 100) # Gray outline for unused spots
|
|
||||||
|
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
cx = count_start_x + i * (circle_diameter + horizontal_spacing)
|
cx = outs_column_x
|
||||||
cy = count_start_y
|
cy = outs_column_start_y + i * (out_circle_diameter + out_vertical_spacing)
|
||||||
coords = [cx, cy, cx + circle_diameter, cy + circle_diameter]
|
coords = [cx, cy, cx + out_circle_diameter, cy + out_circle_diameter]
|
||||||
if i < outs:
|
if i < outs:
|
||||||
draw.ellipse(coords, fill=circle_color_out)
|
draw.ellipse(coords, fill=circle_color_out)
|
||||||
else:
|
else:
|
||||||
# Draw empty outline for remaining spots
|
|
||||||
draw.ellipse(coords, outline=circle_color_empty_outline)
|
draw.ellipse(coords, outline=circle_color_empty_outline)
|
||||||
|
|
||||||
# Draw Team:Score at the bottom
|
# Draw Team:Score at the bottom
|
||||||
|
|||||||
Reference in New Issue
Block a user