Compare commits
No commits in common. "238c74b0ec91a50835021c83eb33f4c0105142d6" and "d9c4401f43ca00c7f800691b25c5ef99617ba77a" have entirely different histories.
238c74b0ec
...
d9c4401f43
@ -1,3 +1 @@
|
||||
__version__ = '0.0.2'
|
||||
|
||||
from . import main
|
||||
__version__ = '0.0.1'
|
@ -1,6 +1,6 @@
|
||||
import sys
|
||||
|
||||
import thermopi
|
||||
from thermopi.screen import main as start
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@ -10,4 +10,4 @@ if __name__ == '__main__':
|
||||
if arg == '--window':
|
||||
windowed_mode = True
|
||||
|
||||
thermopi.main.main(windowed_mode)
|
||||
start(windowed_mode)
|
||||
|
@ -1,46 +0,0 @@
|
||||
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()
|
BIN
thermopi/resources/dial-bg.png
Normal file
BIN
thermopi/resources/dial-bg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 221 KiB |
BIN
thermopi/resources/dial-face.png
Normal file
BIN
thermopi/resources/dial-face.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 752 B |
98
thermopi/screen.py
Normal file
98
thermopi/screen.py
Normal file
@ -0,0 +1,98 @@
|
||||
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()
|
@ -1 +0,0 @@
|
||||
from . import dial
|
@ -1,92 +0,0 @@
|
||||
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()
|
Loading…
Reference in New Issue
Block a user