small refactoring
This commit is contained in:
9
knob.py
9
knob.py
@ -5,8 +5,8 @@ class Knob:
|
||||
|
||||
def __init__(self, screen, color, radius, position):
|
||||
self.screen = screen
|
||||
self.color = color
|
||||
self.radius = radius
|
||||
self.fill_color = color
|
||||
self.position = position
|
||||
self.value = 0
|
||||
|
||||
@ -14,11 +14,12 @@ class Knob:
|
||||
self.value = value
|
||||
|
||||
def get_pointer_position(self):
|
||||
x = self.radius * math.cos((self.value * 0.8 * 2 + 0.7) * math.pi) + self.position[0]
|
||||
y = self.radius * math.sin((self.value * 0.8 * 2 + 0.7) * math.pi) + self.position[1]
|
||||
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]
|
||||
return(x, y)
|
||||
|
||||
def display(self):
|
||||
pygame.draw.circle(self.screen, self.fill_color, self.position, self.radius)
|
||||
pygame.draw.circle(self.screen, self.color, self.position, self.radius)
|
||||
pygame.draw.line(self.screen, "black", self.position, self.get_pointer_position(), 3)
|
||||
|
||||
Reference in New Issue
Block a user