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):
|
def __init__(self, screen, color, radius, position):
|
||||||
self.screen = screen
|
self.screen = screen
|
||||||
|
self.color = color
|
||||||
self.radius = radius
|
self.radius = radius
|
||||||
self.fill_color = color
|
|
||||||
self.position = position
|
self.position = position
|
||||||
self.value = 0
|
self.value = 0
|
||||||
|
|
||||||
@ -14,11 +14,12 @@ class Knob:
|
|||||||
self.value = value
|
self.value = value
|
||||||
|
|
||||||
def get_pointer_position(self):
|
def get_pointer_position(self):
|
||||||
x = self.radius * math.cos((self.value * 0.8 * 2 + 0.7) * math.pi) + self.position[0]
|
angle = (self.value * 0.8 * 2 + 0.7) * math.pi
|
||||||
y = self.radius * math.sin((self.value * 0.8 * 2 + 0.7) * math.pi) + self.position[1]
|
x = self.radius * math.cos(angle) + self.position[0]
|
||||||
|
y = self.radius * math.sin(angle) + self.position[1]
|
||||||
return(x, y)
|
return(x, y)
|
||||||
|
|
||||||
def display(self):
|
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)
|
pygame.draw.line(self.screen, "black", self.position, self.get_pointer_position(), 3)
|
||||||
|
|
||||||
1
main.py
1
main.py
@ -7,6 +7,7 @@ screenW = 561
|
|||||||
screenH = 325
|
screenH = 325
|
||||||
screen = pygame.display.set_mode((screenW, screenH))
|
screen = pygame.display.set_mode((screenW, screenH))
|
||||||
|
|
||||||
|
# Create and position the knobs
|
||||||
knobs_radius = screenW / 25
|
knobs_radius = screenW / 25
|
||||||
knobs_spacing = knobs_radius * 2
|
knobs_spacing = knobs_radius * 2
|
||||||
knobs_x = (screenW - (knobs_radius + knobs_spacing) * 2) / 2
|
knobs_x = (screenW - (knobs_radius + knobs_spacing) * 2) / 2
|
||||||
|
|||||||
Reference in New Issue
Block a user