Compare commits

..

No commits in common. "3aee864b8c2daf24a09535f11e6acc7664486032" and "b9f443c42476b5619813621bfd05ad4db42abc87" have entirely different histories.

6 changed files with 57 additions and 75 deletions

1
Interface/__init__.py Normal file
View File

@ -0,0 +1 @@
from .interface import *

View File

@ -1,59 +0,0 @@
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)

31
Interface/helpers.py Normal file
View File

@ -0,0 +1,31 @@
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

21
Interface/interface.py Normal file
View File

@ -0,0 +1,21 @@
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()

View File

@ -1,14 +0,0 @@
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()

View File

@ -1,3 +1,5 @@
from Interface.vacuum_render import initial_draw import pygame
from Interface import initialize_interface
initial_draw() pygame.init()
initialize_interface(10, 10)