added a label and value surface to display the value of the changing fx

This commit is contained in:
SallarShayegan
2025-02-23 22:37:40 +01:00
parent 106d93b9c3
commit 3424674875
2 changed files with 30 additions and 2 deletions

View File

@ -13,6 +13,12 @@ class Knob:
def set_value(self, value): def set_value(self, value):
self.value = value self.value = value
def set_color(self, color):
self.color = color
def get_position(self):
return self.position
def get_pointer_position(self): def get_pointer_position(self):
angle = (self.value * 0.8 * 2 + 0.7) * math.pi angle = (self.value * 0.8 * 2 + 0.7) * math.pi
x = self.radius * math.cos(angle) + self.position[0] x = self.radius * math.cos(angle) + self.position[0]
@ -21,5 +27,5 @@ class Knob:
def display(self): def display(self):
pygame.draw.circle(self.screen, self.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(), 4)

24
main.py
View File

@ -7,6 +7,9 @@ screenW = 561
screenH = 325 screenH = 325
screen = pygame.display.set_mode((screenW, screenH)) screen = pygame.display.set_mode((screenW, screenH))
color_primary = (0, 190, 180)
color_primary_light = (0, 255, 245)
# Create and position the knobs # Create and position the knobs
knobs_radius = screenW / 25 knobs_radius = screenW / 25
knobs_spacing = knobs_radius * 2 knobs_spacing = knobs_radius * 2
@ -16,12 +19,16 @@ knobs_y = (screenH - (knobs_radius + knobs_spacing) * 3) / 2
y = knobs_y y = knobs_y
knobs = [] knobs = []
for i in range(8): for i in range(8):
knobs.append(Knob(screen, (0, 210, 200), knobs_radius, (x, y))) knobs.append(Knob(screen, color_primary, knobs_radius, (x, y)))
y += knobs_radius + knobs_spacing y += knobs_radius + knobs_spacing
if i == 3 or i == 6: if i == 3 or i == 6:
x += knobs_radius + knobs_spacing x += knobs_radius + knobs_spacing
y = knobs_y y = knobs_y
pygame.font.init() # you have to call this at the start,
# if you want to use this module.
font_helvetica = pygame.font.SysFont('Helvetica', 30)
clock = pygame.time.Clock() clock = pygame.time.Clock()
running = True running = True
@ -36,6 +43,21 @@ while running:
screen.fill("black") screen.fill("black")
# RENDER YOUR GAME HERE # RENDER YOUR GAME HERE
fx_label = font_helvetica.render('REVERB WET', False, color_primary_light)
fx_value = font_helvetica.render('[ 86% ]', False, color_primary_light)
label_x = screenW - fx_label.get_width() - 20
label_y = (screenH - fx_label.get_height() - fx_value.get_height()) / 2
screen.blit(fx_label, (label_x, label_y))
screen.blit(fx_value, (label_x, screenH / 2))
pygame.draw.line(screen, color_primary_light, (label_x - 10, label_y), (label_x - 10, screenH - label_y), 2)
pygame.draw.line(screen, color_primary_light, (knobs_x + knobs_radius * 1.5, screenH/2), (label_x - 10, screenH/2), 2)
pygame.draw.line(screen, color_primary_light, knobs[2].get_position(), (knobs_x + knobs_radius * 1.5, screenH/2), 2)
knobs[2].set_value(0.86)
knobs[2].set_color(color_primary_light)
for i in range(8): for i in range(8):
knobs[i].display() knobs[i].display()