diff --git a/Interface/__init__.py b/Interface/__init__.py deleted file mode 100644 index e07b40a..0000000 --- a/Interface/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .interface import * diff --git a/Interface/grid_draw.py b/Interface/grid_draw.py new file mode 100644 index 0000000..92471f9 --- /dev/null +++ b/Interface/grid_draw.py @@ -0,0 +1,59 @@ +import sys +import pygame + +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 wrap(*args, **kwargs): + 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 + ): + 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)) + + def start_draw(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: sys.exit() + self.screen.fill(Colors.BLACK) + + def end_draw(self): + pygame.display.flip() + + @default_color + 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): + tiles_width = self.width / tiles_x + tiles_height = self.height / tiles_y + + for i in range(1, tiles_x): + self.line(tiles_width * i, 0, tiles_width * i, self.height, color=color) + + for i in range(1, tiles_y): + 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 diff --git a/Interface/helpers.py b/Interface/helpers.py deleted file mode 100644 index 43e1ced..0000000 --- a/Interface/helpers.py +++ /dev/null @@ -1,31 +0,0 @@ -import pygame - -BLACK = 0, 0, 0 -WHITE = 255, 255, 255 - - -def rect(screen, color, position_x, position_y, size_x, size_y): - pygame.draw.rect(screen, color, (position_x, position_y, size_x, size_y)) - - -def line(screen, color, x_1, y_1, x_2, y_2): - pygame.draw.line(screen, color, (x_1, y_1), (x_2, y_2)) - - -def create_screen(size): - return pygame.display.set_mode(size) - - -def draw_board(screen, color, width, height, tiles_x, tiles_y): - tiles_width = width / tiles_x - tiles_height = height / tiles_y - - temp_x = tiles_width - for i in range(tiles_x-1): - line(screen, color, temp_x, 0, temp_x, height) - temp_x += tiles_width - - temp_y = tiles_height - for i in range(tiles_y-1): - line(screen, color, 0, temp_y, width, temp_y) - temp_y += tiles_height diff --git a/Interface/interface.py b/Interface/interface.py deleted file mode 100644 index fe7971a..0000000 --- a/Interface/interface.py +++ /dev/null @@ -1,21 +0,0 @@ -import sys -import pygame -from .helpers import * - - -def initialize_interface(tiles_x, tiles_y): - size = width, height = 800, 800 - screen = create_screen(size) - pygame.display.set_caption('Epic AI Vacuum Cleaner') - - while True: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - sys.exit() - - screen.fill(BLACK) - # rect(screen, WHITE, 50,50,90,90) - - draw_board(screen, WHITE, width, height, tiles_x, tiles_y) - - pygame.display.flip() diff --git a/Interface/vacuum_render.py b/Interface/vacuum_render.py new file mode 100644 index 0000000..29f1b52 --- /dev/null +++ b/Interface/vacuum_render.py @@ -0,0 +1,14 @@ +from Interface.grid_draw import GridDraw, Colors + +# dummy function +def initial_draw(): + grid = GridDraw(500, 500) + + while True: + grid.start_draw() + + grid.board(10, 10) + grid.circle(75, 75, 20, color=Colors.RED) + grid.circle(225, 175, 20, color=Colors.GREEN) + + grid.end_draw() diff --git a/main.py b/main.py index 7ad26ad..45c51de 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,3 @@ -import pygame -from Interface import initialize_interface +from Interface.vacuum_render import initial_draw -pygame.init() -initialize_interface(10, 10) +initial_draw() \ No newline at end of file