diff --git a/thermopi/__init__.py b/thermopi/__init__.py index 99c4176..1c2d4f6 100644 --- a/thermopi/__init__.py +++ b/thermopi/__init__.py @@ -1 +1,3 @@ -__version__ = '0.0.1' \ No newline at end of file +__version__ = '0.0.1' + +from . import main diff --git a/thermopi/__main__.py b/thermopi/__main__.py index cdd9d22..d8b2eae 100644 --- a/thermopi/__main__.py +++ b/thermopi/__main__.py @@ -1,6 +1,6 @@ import sys -from thermopi.screen import main as start +import thermopi if __name__ == '__main__': @@ -10,4 +10,4 @@ if __name__ == '__main__': if arg == '--window': windowed_mode = True - start(windowed_mode) + thermopi.main.main(windowed_mode) diff --git a/thermopi/main.py b/thermopi/main.py new file mode 100644 index 0000000..2137698 --- /dev/null +++ b/thermopi/main.py @@ -0,0 +1,44 @@ +import pygame +import os +import thermopi.surfaces as surfaces + +SCREEN_SIZE = (720, 720) +DIAL_SIZE = int(min(SCREEN_SIZE[0], SCREEN_SIZE[1]) * 0.9) +FPS = 60 +PI = 3.14159265 +VALID_SURFACES = [ + 'dial' +] + +script_dir = os.path.dirname(os.path.abspath(__file__)) + + +def main(windowed_mode): + pygame.init() + clock = pygame.time.Clock() + if windowed_mode: + window = pygame.display.set_mode(SCREEN_SIZE) + else: + window = pygame.display.set_mode(SCREEN_SIZE, pygame.FULLSCREEN) + + surface = getattr(globals()['surfaces'], 'dial').Surface(SCREEN_SIZE) + running = True + while running: + clock.tick(FPS) + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + running = False + + window.blit(surface, surface.get_rect()) + + if not surface.running: + next_surface = surface.next_surface + if next_surface not in VALID_SURFACES: + raise Exception('Given surface is not a valid surface!') + surface = getattr(globals()['surfaces'], next_surface).Surface(SCREEN_SIZE) + + pygame.quit() diff --git a/thermopi/resources/dial-bg.png b/thermopi/resources/dial-bg.png deleted file mode 100644 index 7409c2f..0000000 Binary files a/thermopi/resources/dial-bg.png and /dev/null differ diff --git a/thermopi/resources/dial-face.png b/thermopi/resources/dial-face.png deleted file mode 100644 index ea26071..0000000 Binary files a/thermopi/resources/dial-face.png and /dev/null differ diff --git a/thermopi/screen.py b/thermopi/screen.py deleted file mode 100644 index 7a1c4e6..0000000 --- a/thermopi/screen.py +++ /dev/null @@ -1,98 +0,0 @@ -import math -import pygame -import os - -DIAL_SIZE = 500 -SCREEN_SIZE = 720 -FPS = 60 -PI = 3.14159265 - -script_dir = os.path.dirname(os.path.abspath(__file__)) - - -class Dial(pygame.sprite.Sprite): - def __init__(self): - super().__init__() - self._base_image = pygame.image.load(script_dir + '/resources/dial-face.png') - self.position = 0 - self.rotation = 77 - (2 * 77.5 * self.position) - self.image = pygame.transform.rotate(self._base_image, self.rotation) - self.rect = self._base_image.get_rect() - self.test_cw = True - self.test = True - - def update(self): - self.rotation = 77 - (2 * 77.5 * self.position) - self.image = pygame.transform.rotate(self._base_image, self.rotation) - self.rect = self.image.get_rect(center=self.rect.center) - self.rect.center = (math.sin(math.radians(self.rotation)) * -300 + 360, - math.cos(math.radians(self.rotation + 180)) * 300 + 360) - - def move_dial(self, movement_ammount): - self.position += movement_ammount - - if self.position > 1: - self.position = 1 - if self.position < 0: - self.position = 0 - - -def main(windowed_mode): - pygame.init() - clock = pygame.time.Clock() - if windowed_mode: - window = pygame.display.set_mode((SCREEN_SIZE, SCREEN_SIZE)) - else: - window = pygame.display.set_mode((SCREEN_SIZE, SCREEN_SIZE), pygame.FULLSCREEN) - - bg_image = pygame.image.load(script_dir + '/resources/dial-bg.png') - - dial = Dial() - - all_sprites = pygame.sprite.Group(dial) - - def draw(): - # Draws all the sprites on a black background - all_sprites.update() - window.blit(bg_image, (0, 0)) - all_sprites.draw(window) - - # Update the entire display - pygame.display.flip() - - running = True - prev_mouse_pos = (0, 0) - mouse_pos = (0, 0) - get_mouse_speed = False - pygame.mouse.set_visible(False) - - while running: - clock.tick(FPS) - prev_mouse_pos = mouse_pos - mouse_pos = pygame.mouse.get_pos() - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - running = False - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_ESCAPE: - running = False - if event.type == pygame.MOUSEBUTTONDOWN: - get_mouse_speed = True - mouse_pos = pygame.mouse.get_pos() - prev_mouse_pos = mouse_pos - if event.type == pygame.MOUSEBUTTONUP: - get_mouse_speed = False - - draw() - if get_mouse_speed: - mouse_diff = (prev_mouse_pos[0] - mouse_pos[0], prev_mouse_pos[1] - mouse_pos[1]) - movement_speed = math.sqrt((mouse_diff[0] ** 2) + (mouse_diff[1] ** 2)) - mouse_angle = math.atan2(mouse_pos[0] - 360, mouse_pos[1] - 360) - diff_angle = math.atan2(mouse_diff[0], mouse_diff[1]) - speed_coeff = math.cos((mouse_angle - (0.5 * PI)) - diff_angle) - final_speed = movement_speed * speed_coeff - dial.move_dial(final_speed / -3000.0) - - - pygame.quit() diff --git a/thermopi/surfaces/__init__.py b/thermopi/surfaces/__init__.py new file mode 100644 index 0000000..fad08b8 --- /dev/null +++ b/thermopi/surfaces/__init__.py @@ -0,0 +1 @@ +from . import dial \ No newline at end of file diff --git a/thermopi/surfaces/dial.py b/thermopi/surfaces/dial.py new file mode 100644 index 0000000..430d09e --- /dev/null +++ b/thermopi/surfaces/dial.py @@ -0,0 +1,11 @@ +import pygame + + +class Surface(pygame.Surface): + def __init__(self, window_size): + super().__init__(window_size, pygame.SRCALPHA) + self.running = True + self.next_surface = '' + + def update(self): + self.fill((0, 0, 0))