Moving-circle #3

Merged
s473566 merged 4 commits from Moving-circle into main 2023-03-12 18:22:26 +01:00
5 changed files with 75 additions and 36 deletions
Showing only changes of commit 0580148281 - Show all commits

View File

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

59
Interface/grid_draw.py Normal file
View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -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()