59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
|
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)
|