97 lines
3.0 KiB
Python
97 lines
3.0 KiB
Python
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
|
|
while running:
|
|
clock.tick(FPS)
|
|
|
|
# pygame.mouse.set_visible(False)
|
|
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
|
|
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 / -5000.0)
|
|
|
|
|
|
pygame.quit()
|