31 lines
873 B
Python
31 lines
873 B
Python
import pygame
|
|
import math
|
|
|
|
class Knob:
|
|
|
|
def __init__(self, screen, color, radius, position):
|
|
self.screen = screen
|
|
self.color = color
|
|
self.radius = radius
|
|
self.position = position
|
|
self.value = 0
|
|
|
|
def set_value(self, value):
|
|
self.value = value
|
|
|
|
def set_color(self, color):
|
|
self.color = color
|
|
|
|
def get_position(self):
|
|
return self.position
|
|
|
|
def get_pointer_position(self):
|
|
angle = (self.value * 0.8 * 2 + 0.7) * math.pi
|
|
x = (self.radius - 5) * math.cos(angle) + self.position[0]
|
|
y = (self.radius - 5) * math.sin(angle) + self.position[1]
|
|
return(x, y)
|
|
|
|
def display(self):
|
|
pygame.draw.circle(self.screen, self.color, self.position, self.radius)
|
|
pygame.draw.line(self.screen, "black", self.position, self.get_pointer_position(), 4)
|
|
|