From 948617b22813591ae5212eed40914f1ed70a8b19 Mon Sep 17 00:00:00 2001 From: Linxi Li Date: Sat, 22 Jan 2022 13:40:47 -0500 Subject: [PATCH] [+] A1 P2 Draw node --- assignments/A1/a1_part2.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/assignments/A1/a1_part2.py b/assignments/A1/a1_part2.py index 01a4ea9..6433f91 100644 --- a/assignments/A1/a1_part2.py +++ b/assignments/A1/a1_part2.py @@ -123,6 +123,21 @@ def draw_node(screen: pygame.Surface, node: _Node, pos: Tuple[int, int]) -> None We strongly recommend initializing new constants at the top of this file to represent node width, height, and colour. """ + x, y = pos + p = PADDING_PX + + # Calculate side length + xp, yp = x + p, y + p + sl = GRID_WIDTH // 2 - p + + # Draw outer border + pygame.draw.rect(screen, COLOR, (xp, yp, sl, sl), LINE_WIDTH) + + # Draw separation line + pygame.draw.rect(screen, COLOR, (xp + sl - LINE_WIDTH, yp, sl, sl), LINE_WIDTH) + + # Draw text (centered) + draw_text_centered(screen, str(node.item), (xp + sl // 2, yp + sl // 2)) def draw_link(screen: pygame.Surface, start: Tuple[int, int], end: Tuple[int, int]) -> None: