From 4442bed2c2c4fbc43bf779854e9c0fb8a3f64ee3 Mon Sep 17 00:00:00 2001 From: nickedyer Date: Sun, 19 Feb 2023 19:14:07 -0500 Subject: [PATCH] change dial face to only move small triangle to improve performance --- thermopi/screen.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/thermopi/screen.py b/thermopi/screen.py index 88ededa..041d3a4 100644 --- a/thermopi/screen.py +++ b/thermopi/screen.py @@ -1,3 +1,5 @@ +import math + import pygame import os @@ -13,23 +15,28 @@ class Dial(pygame.sprite.Sprite): def __init__(self): super().__init__() self._base_image = pygame.image.load(script_dir + '/resources/dial-face.png') - self.rotation = 0 - self.image = pygame.transform.rotate(self._base_image, 77-(2*77.5*self.rotation)) + 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 + def update(self): if self.test_cw: - self.rotation += 0.01 + self.position += 0.01 else: - self.rotation -= 0.01 - if self.rotation > 1: - self.rotation = 1 + self.position -= 0.01 + if self.position > 1: + self.position = 1 self.test_cw = not self.test_cw - if self.rotation < 0: - self.rotation = 0 + if self.position < 0: + self.position = 0 self.test_cw = not self.test_cw - self.image = pygame.transform.rotate(self._base_image, 77-(2*77.5*self.rotation)) + 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 main(windowed_mode):