79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
import pygame
|
|
|
|
# Constants
|
|
C_GRID_L_VALUE = 200
|
|
C_GRID_D_VALUE = 100
|
|
C_MPLOT_START = 50
|
|
|
|
gridLight = pygame.Color(C_GRID_L_VALUE, C_GRID_L_VALUE, C_GRID_L_VALUE)
|
|
gridDark = pygame.Color(C_GRID_D_VALUE, C_GRID_D_VALUE, C_GRID_D_VALUE)
|
|
font_h = pygame.font.SysFont(None, 28)
|
|
font_m = pygame.font.SysFont(None, 16)
|
|
|
|
|
|
# UI Class
|
|
class SimUI:
|
|
def __init__(self, screen, pole):
|
|
self.screen = screen
|
|
self.pole = pole
|
|
|
|
self.metaPlotY = 50
|
|
|
|
def meta(self, val, desc):
|
|
self.screen.blit(
|
|
font_m.render(f"{desc} = {val}", True, "black"), (15, self.metaPlotY)
|
|
)
|
|
self.metaPlotY += 15
|
|
|
|
def grid(self, dist, Xoff=0, Yoff=0):
|
|
self.screen.fill("white")
|
|
cXoff = self.pole.x % dist
|
|
cYoff = self.pole.y % dist
|
|
|
|
for i in range(0, 1280, dist):
|
|
pygame.draw.line(
|
|
self.screen,
|
|
gridLight,
|
|
(i + Xoff + cXoff, 0),
|
|
(i + Xoff + cXoff, 720),
|
|
1,
|
|
)
|
|
pygame.draw.line(
|
|
self.screen,
|
|
gridLight,
|
|
(0, i + Yoff + cYoff),
|
|
(1280, i + Yoff + cYoff),
|
|
1,
|
|
)
|
|
|
|
pygame.draw.line(
|
|
self.screen, gridDark, (self.pole.x + Xoff, 0), (self.pole.x + Xoff, 720), 1
|
|
)
|
|
pygame.draw.line(
|
|
self.screen,
|
|
gridDark,
|
|
(0, self.pole.y + Yoff),
|
|
(1280, self.pole.y + Yoff),
|
|
1,
|
|
)
|
|
|
|
def centeredText(self, font, text="", colour="black", y=0):
|
|
textObj = font.render(text, True, colour)
|
|
text_rect = textObj.get_rect(center=(1280 / 2, 720 / 2 - y))
|
|
self.screen.blit(textObj, text_rect)
|
|
|
|
def wasted(self):
|
|
font_g = pygame.font.SysFont(None, 128)
|
|
self.centeredText(font_g, "WASTED", "red", 100)
|
|
self.centeredText(font_m, "Press space to restart", "black", 60)
|
|
self.centeredText(font_m, "Press G to view nerd graphs", "black", 45)
|
|
|
|
def update(self):
|
|
self.screen.blit(
|
|
font_h.render("Pendulum simulator 4000", True, "black"), (10, 10)
|
|
)
|
|
self.screen.blit(
|
|
font_m.render("Arne van Iterson, 2023", True, "black"), (1150, 700)
|
|
)
|
|
self.metaPlotY = C_MPLOT_START
|