2023-03-12 02:07:20 +01:00
|
|
|
import sys
|
|
|
|
import pygame
|
|
|
|
|
2023-03-16 20:33:22 +01:00
|
|
|
|
|
|
|
class Colors:
|
2023-03-12 02:07:20 +01:00
|
|
|
BLACK = 0, 0, 0
|
|
|
|
WHITE = 255, 255, 255
|
|
|
|
RED = 255, 0, 0
|
|
|
|
GREEN = 0, 255, 0
|
|
|
|
|
2023-03-16 20:33:22 +01:00
|
|
|
|
2023-03-12 02:07:20 +01:00
|
|
|
DEFAULT_COLOR = Colors.WHITE
|
2023-03-19 22:00:10 +01:00
|
|
|
RADIUS_SIZE_COEFFICIENT = 3
|
2023-03-12 02:07:20 +01:00
|
|
|
|
2023-03-16 20:33:22 +01:00
|
|
|
|
|
|
|
def default_color(func):
|
2023-03-12 02:07:20 +01:00
|
|
|
def wrap(*args, **kwargs):
|
2023-03-16 20:33:22 +01:00
|
|
|
if "color" not in kwargs:
|
|
|
|
kwargs["color"] = DEFAULT_COLOR
|
2023-03-12 02:07:20 +01:00
|
|
|
result = func(*args, **kwargs)
|
|
|
|
return result
|
2023-03-16 20:33:22 +01:00
|
|
|
|
2023-03-12 02:07:20 +01:00
|
|
|
return wrap
|
|
|
|
|
2023-03-16 20:33:22 +01:00
|
|
|
|
|
|
|
class GridDraw:
|
|
|
|
def __init__(self, width=None, height=None, background=None):
|
2023-03-12 02:07:20 +01:00
|
|
|
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
|
2023-03-16 20:33:22 +01:00
|
|
|
|
2023-03-12 02:07:20 +01:00
|
|
|
pygame.init()
|
|
|
|
self.screen = pygame.display.set_mode((self.width, self.height))
|
|
|
|
|
|
|
|
def start_draw(self):
|
|
|
|
self.screen.fill(Colors.BLACK)
|
|
|
|
|
|
|
|
def end_draw(self):
|
|
|
|
pygame.display.flip()
|
|
|
|
|
|
|
|
@default_color
|
2023-03-16 20:33:22 +01:00
|
|
|
def line(self, x_1, y_1, x_2, y_2, color=None):
|
2023-03-12 02:07:20 +01:00
|
|
|
pygame.draw.line(self.screen, color, (x_1, y_1), (x_2, y_2))
|
2023-03-16 20:33:22 +01:00
|
|
|
|
2023-03-12 02:07:20 +01:00
|
|
|
@default_color
|
2023-03-16 20:33:22 +01:00
|
|
|
def board(self, tiles_x, tiles_y, color=None):
|
2023-03-12 02:07:20 +01:00
|
|
|
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
|
2023-03-19 22:00:10 +01:00
|
|
|
def circle(self, x, y, tile_height, color=None):
|
|
|
|
radius = tile_height / RADIUS_SIZE_COEFFICIENT
|
|
|
|
pygame.draw.circle(self.screen, color, (x, y), radius)
|