From 101136b0b7f3d00a26c84b36b7b8c386e28d9e0b Mon Sep 17 00:00:00 2001 From: Mateusz Dokowicz Date: Sun, 19 Mar 2023 22:00:10 +0100 Subject: [PATCH] radius Fix --- Interface/grid_draw.py | 8 ++++---- Interface/vacuum_render.py | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Interface/grid_draw.py b/Interface/grid_draw.py index 5335dee..b40a406 100644 --- a/Interface/grid_draw.py +++ b/Interface/grid_draw.py @@ -10,6 +10,7 @@ class Colors: DEFAULT_COLOR = Colors.WHITE +RADIUS_SIZE_COEFFICIENT = 3 def default_color(func): @@ -53,7 +54,6 @@ class GridDraw: self.line(0, tiles_height * i, self.width, tiles_height * i, color=color) @default_color - def circle(self, x, y, radius, color=None): - pygame.draw.circle( - self.screen, color, (x, y), radius - ) # TODO calculate radius (now 20) in terms of window size. + def circle(self, x, y, tile_height, color=None): + radius = tile_height / RADIUS_SIZE_COEFFICIENT + pygame.draw.circle(self.screen, color, (x, y), radius) diff --git a/Interface/vacuum_render.py b/Interface/vacuum_render.py index b5007fe..6d9bc79 100644 --- a/Interface/vacuum_render.py +++ b/Interface/vacuum_render.py @@ -4,31 +4,35 @@ import pygame from Interface.movement import robot_movement -def initial_draw(grid_dimensions, board_size): +# window_dimensions says how many pixels window have +# board_size says how many lines board have +def initial_draw(window_dimensions, board_size): # window name pygame.display.set_caption("AI Vacuum Cleaner") # define array for grid - border_array = [["" for j in range(board_size)] for i in range(board_size)] + board_array = [["" for j in range(board_size)] for i in range(board_size)] + board_render(board_array) # set window dimension - grid_width = grid_dimensions - grid_height = grid_dimensions + window_width = window_dimensions + window_height = window_dimensions # FIXME @countingthedots: please tell me what is going on there and why??? - # - grid = GridDraw(grid_width, grid_height) - tile_width = grid_width / board_size - tile_height = grid_height / board_size + # + grid = GridDraw(window_width, window_height) + tile_width = window_width / board_size + tile_height = window_height / board_size x = tile_width / 2 y = tile_height / 2 - radius = tile_height/3 # rendering loop while True: grid.start_draw() grid.board(board_size, board_size) - (x, y) = robot_movement(grid_width, grid_height, tile_width, tile_height, x, y) - grid.circle(x, y, radius, color=Colors.RED) + (x, y) = robot_movement( + window_width, window_height, tile_width, tile_height, x, y + ) + grid.circle(x, y, tile_height, color=Colors.RED) grid.end_draw() pygame.time.delay(10)