2025-02-23 16:17:11 +01:00
|
|
|
import pygame
|
2025-02-23 17:05:46 +01:00
|
|
|
import math
|
2025-02-23 16:17:11 +01:00
|
|
|
|
|
|
|
|
class Knob:
|
|
|
|
|
|
2025-02-23 20:46:34 +01:00
|
|
|
def __init__(self, screen, color, radius, position):
|
2025-02-23 16:17:11 +01:00
|
|
|
self.screen = screen
|
2025-02-23 21:11:49 +01:00
|
|
|
self.color = color
|
2025-02-23 20:46:34 +01:00
|
|
|
self.radius = radius
|
|
|
|
|
self.position = position
|
2025-02-23 20:10:03 +01:00
|
|
|
self.value = 0
|
2025-02-23 17:05:46 +01:00
|
|
|
|
|
|
|
|
def set_value(self, value):
|
|
|
|
|
self.value = value
|
|
|
|
|
|
2025-02-23 22:37:40 +01:00
|
|
|
def set_color(self, color):
|
|
|
|
|
self.color = color
|
|
|
|
|
|
|
|
|
|
def get_position(self):
|
|
|
|
|
return self.position
|
|
|
|
|
|
2025-02-23 17:05:46 +01:00
|
|
|
def get_pointer_position(self):
|
2025-02-23 21:11:49 +01:00
|
|
|
angle = (self.value * 0.8 * 2 + 0.7) * math.pi
|
|
|
|
|
x = self.radius * math.cos(angle) + self.position[0]
|
|
|
|
|
y = self.radius * math.sin(angle) + self.position[1]
|
2025-02-23 17:05:46 +01:00
|
|
|
return(x, y)
|
2025-02-23 16:17:11 +01:00
|
|
|
|
|
|
|
|
def display(self):
|
2025-02-23 21:11:49 +01:00
|
|
|
pygame.draw.circle(self.screen, self.color, self.position, self.radius)
|
2025-02-23 22:37:40 +01:00
|
|
|
pygame.draw.line(self.screen, "black", self.position, self.get_pointer_position(), 4)
|
2025-02-23 16:17:11 +01:00
|
|
|
|