From 77e92bf273cc1dbc93e80e17c6c0025c17bef720 Mon Sep 17 00:00:00 2001 From: SallarShayegan Date: Mon, 24 Feb 2025 12:15:20 +0100 Subject: [PATCH] added the display_label method including the implementation of the visual path from the knobs to the label --- knob.py | 4 ++-- main.py | 53 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/knob.py b/knob.py index f6b2a9f..20d50fd 100644 --- a/knob.py +++ b/knob.py @@ -21,8 +21,8 @@ class Knob: def get_pointer_position(self): 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] + 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): diff --git a/main.py b/main.py index 4c2f231..6c5029b 100644 --- a/main.py +++ b/main.py @@ -32,6 +32,45 @@ font_helvetica = pygame.font.SysFont('Helvetica', 30) clock = pygame.time.Clock() running = True +def display_label(index): + 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) + + line_points = [] + line_points.append(knobs[index].get_position()) + + if (index == 0 or index == 1 or index == 4 or index == 5): + x = knobs[index].get_position()[0] + knobs_radius * 1.5 + y = knobs[index].get_position()[1] + knobs_radius * 1.5 + line_points.append((x, y)) + elif (index == 2 or index == 3 or index == 6): + x = knobs[index].get_position()[0] + knobs_radius * 1.5 + y = knobs[index].get_position()[1] - knobs_radius * 1.5 + line_points.append((x, y)) + elif (index == 7): + x = knobs[index].get_position()[0] - knobs_radius * 1.5 + y = knobs[index].get_position()[1] + knobs_radius * 1.5 + line_points.append((x, y)) + + if (index == 0 or index == 3): + line_points.append((knobs_x + knobs_radius * 1.5, screenH/2)) + elif (index == 4 or index == 6 or index == 7): + line_points.append((knobs[4].get_position()[0] + knobs_radius * 1.5, screenH/2)) + + line_points.append((label_x - 10, screenH/2)) + + for i in range(len(line_points)-1): + pygame.draw.line(screen, color_primary_light, line_points[i], line_points[i+1], 2) + + knobs[index].set_value(0.86) + knobs[index].set_color(color_primary_light) + while running: # poll for events # pygame.QUIT event means the user clicked X to close your window @@ -44,19 +83,7 @@ while running: # 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) + display_label(7) for i in range(8): knobs[i].display()