From d080b047633cb91e7b220e252cea3dcb07536ecf Mon Sep 17 00:00:00 2001 From: Mateusz Dokowicz Date: Thu, 16 Mar 2023 20:33:22 +0100 Subject: [PATCH] formatting and comments --- Interface/grid_draw.py | 34 +++++++++++++++++----------------- Interface/movement.py | 20 ++++++++++++++------ Interface/vacuum_render.py | 11 ++++++----- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/Interface/grid_draw.py b/Interface/grid_draw.py index 0f74e86..e3900e7 100644 --- a/Interface/grid_draw.py +++ b/Interface/grid_draw.py @@ -1,33 +1,33 @@ import sys import pygame -class Colors(): + +class Colors: BLACK = 0, 0, 0 WHITE = 255, 255, 255 RED = 255, 0, 0 GREEN = 0, 255, 0 + DEFAULT_COLOR = Colors.WHITE -def default_color(func): + +def default_color(func): def wrap(*args, **kwargs): - if 'color' not in kwargs: - kwargs['color'] = DEFAULT_COLOR + if "color" not in kwargs: + kwargs["color"] = DEFAULT_COLOR result = func(*args, **kwargs) return result + return wrap -class GridDraw(): - def __init__( - self, - width = None, - height = None, - background = None - ): + +class GridDraw: + def __init__(self, width=None, height=None, background=None): self.width = width if width != None else 100 self.height = height if height != None else 100 self.background = background if background != None else Colors.BLACK - + pygame.init() self.screen = pygame.display.set_mode((self.width, self.height)) @@ -38,11 +38,11 @@ class GridDraw(): pygame.display.flip() @default_color - def line(self, x_1, y_1, x_2, y_2, color = None): + def line(self, x_1, y_1, x_2, y_2, color=None): pygame.draw.line(self.screen, color, (x_1, y_1), (x_2, y_2)) - + @default_color - def board(self, tiles_x, tiles_y, color = None): + def board(self, tiles_x, tiles_y, color=None): tiles_width = self.width / tiles_x tiles_height = self.height / tiles_y @@ -53,5 +53,5 @@ 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) \ No newline at end of file + def circle(self, x, y, radius, color=None): + pygame.draw.circle(self.screen, color, (x, y), radius) diff --git a/Interface/movement.py b/Interface/movement.py index cbcd2c0..a984e56 100644 --- a/Interface/movement.py +++ b/Interface/movement.py @@ -1,17 +1,25 @@ import pygame import sys -def moving_cleaner(grid_width, grid_height,tile_width,tile_height, x, y): + +def moving_cleaner(grid_width, grid_height, tile_width, tile_height, x, y): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: - if event.key == pygame.K_LEFT and x>(tile_width / 2): + # go left + if event.key == pygame.K_LEFT and x > (tile_width / 2): x -= tile_width - if event.key == pygame.K_RIGHT and x<(grid_width-(tile_width / 2)): + + # go right + if event.key == pygame.K_RIGHT and x < (grid_width - (tile_width / 2)): x += tile_width - if event.key == pygame.K_UP and y>(tile_height / 2): + + # go up + if event.key == pygame.K_UP and y > (tile_height / 2): y -= tile_height - if event.key == pygame.K_DOWN and y<(grid_height-(tile_height / 2)): + + # go down + if event.key == pygame.K_DOWN and y < (grid_height - (tile_height / 2)): y += tile_height - return(x,y) + return (x, y) diff --git a/Interface/vacuum_render.py b/Interface/vacuum_render.py index e19baac..7e28bd8 100644 --- a/Interface/vacuum_render.py +++ b/Interface/vacuum_render.py @@ -3,7 +3,7 @@ import sys import pygame from Interface.movement import moving_cleaner -# dummy function + def initial_draw(grid_width, grid_height): grid = GridDraw(grid_width, grid_height) tile_width = grid_width / 10 @@ -11,11 +11,12 @@ def initial_draw(grid_width, grid_height): x = tile_width / 2 y = tile_height / 2 radius = 15 + + # rendering loop while True: grid.start_draw() grid.board(10, 10) - (x,y) = moving_cleaner(grid_width,grid_height,tile_width,tile_height, x, y) + (x, y) = moving_cleaner(grid_width, grid_height, tile_width, tile_height, x, y) grid.circle(x, y, 20, color=Colors.RED) - grid.end_draw() - pygame.time.delay(10) - + grid.end_draw() + pygame.time.delay(10)