Compare commits

..

4 Commits

Author SHA1 Message Date
238c74b0ec
updated to version 0.0.2 2023-02-20 00:11:14 -05:00
f23572d4d2
added mouse movement 2023-02-20 00:09:31 -05:00
778c373809
added a new dial 2023-02-19 23:55:41 -05:00
ec3c3b66ed
addded surface switching system, removed all gui objects 2023-02-19 22:49:49 -05:00
8 changed files with 144 additions and 101 deletions

View File

@ -1 +1,3 @@
__version__ = '0.0.1'
__version__ = '0.0.2'
from . import main

View File

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

46
thermopi/main.py Normal file
View File

@ -0,0 +1,46 @@
import pygame
import os
import thermopi.surfaces as surfaces
# Global variables
SCREEN_SIZE = (720, 720)
FPS = 60
PI = 3.14159265
VALID_SURFACES = [
'dial'
]
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
def main(windowed_mode=False):
"""
Main looping method.
:param windowed_mode: boolean to start the game in 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)
# Starts the program with the surface 'dial' as the default
surface = getattr(globals()['surfaces'], 'dial').Surface(SCREEN_SIZE)
running = True
while running:
clock.tick(FPS)
surface.update()
window.blit(surface, surface.get_rect())
if not surface.running:
if surface.quit:
break
# Switch the surface to a new surface
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.display.flip()
pygame.quit()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 752 B

View File

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

View File

@ -0,0 +1 @@
from . import dial

92
thermopi/surfaces/dial.py Normal file
View File

@ -0,0 +1,92 @@
import math
import pygame
DIAL_SCALING = 0.9
class Dial(pygame.Surface):
def __init__(self, dial_size):
super().__init__((dial_size, dial_size), pygame.SRCALPHA)
self.rect = self.get_rect()
self.dial_size = dial_size
self.center = (self.dial_size / 2, self.dial_size / 2)
self.setting = 1
def update(self):
self.fill((0, 0, 0, 0))
pygame.draw.circle(self, (0, 255, 0), self.center, self.dial_size / 2, 5)
pygame.draw.circle(self, (64, 64, 64), self.center, self.dial_size / 2 * 0.95)
angle = (1.25 - (1.5 * self.setting)) * math.pi
x_1 = (math.cos(angle) * self.dial_size / 2 * 0.8) + (self.dial_size / 2)
y_1 = (-1 * math.sin(angle) * self.dial_size / 2 * 0.8) + (self.dial_size / 2)
x_2 = (math.cos(angle) * self.dial_size / 2 * 0.99) + (self.dial_size / 2)
y_2 = (-1 * math.sin(angle) * self.dial_size / 2 * 0.99) + (self.dial_size / 2)
pygame.draw.line(self, (0, 255, 0), (x_1, y_1), (x_2, y_2), 10)
def set_setting(self, new_setting):
self.setting = max(0, min(new_setting, 1))
def move_dial(self, movement_amount):
self.setting = max(0, min(self.setting + movement_amount, 1))
class MouseHandler:
def __init__(self):
self.prev_mouse_pos = pygame.mouse.get_pos()
self.mouse_pos = pygame.mouse.get_pos()
self.active = False
def update(self):
self.prev_mouse_pos = self.mouse_pos
self.mouse_pos = pygame.mouse.get_pos()
def get_circular_speed(self, center):
mouse_diff = (self.prev_mouse_pos[0] - self.mouse_pos[0], self.prev_mouse_pos[1] - self.mouse_pos[1])
movement_speed = math.sqrt((mouse_diff[0] ** 2) + (mouse_diff[1] ** 2))
mouse_angle = math.atan2(self.mouse_pos[0] - center[0], self.mouse_pos[1] - center[1])
diff_angle = math.atan2(mouse_diff[0], mouse_diff[1])
speed_coeff = math.cos((mouse_angle - (0.5 * math.pi)) - diff_angle)
final_speed = movement_speed * speed_coeff
return final_speed
class Surface(pygame.Surface):
def __init__(self, window_size):
super().__init__(window_size, pygame.SRCALPHA)
self.running = True
self.quit = False
self.next_surface = ''
dial_size = int(min(window_size[0], window_size[1]) * 0.9)
self.dial = Dial(dial_size)
self.dial.rect.center = (window_size[0] / 2, window_size[1] / 2)
self.mouse_handler = MouseHandler()
def update(self):
self.fill((32, 32, 32))
self.mouse_handler.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
self.quit = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.quit = True
if event.type == pygame.MOUSEBUTTONDOWN:
self.mouse_handler.active = True
self.mouse_handler.prev_mouse_pos = self.mouse_handler.mouse_pos
print('yug')
if event.type == pygame.MOUSEBUTTONUP:
self.mouse_handler.active = False
if self.mouse_handler.active:
self.dial.move_dial(self.mouse_handler.get_circular_speed(self.dial.center) / -3000.0)
self.blit(self.dial, self.dial.rect)
self.dial.update()