added and positioned an array of 8 knobs

This commit is contained in:
SallarShayegan
2025-02-23 20:46:34 +01:00
parent e80152716b
commit 1e0d5de886
2 changed files with 21 additions and 6 deletions

View File

@ -3,11 +3,11 @@ import math
class Knob: class Knob:
def __init__(self, screen): def __init__(self, screen, color, radius, position):
self.screen = screen self.screen = screen
self.radius = screen.get_width()/20 self.radius = radius
self.fill_color = (160,0,255) self.fill_color = color
self.position = (screen.get_width()/2, screen.get_height()/2) self.position = position
self.value = 0 self.value = 0
def set_value(self, value): def set_value(self, value):

19
main.py
View File

@ -6,7 +6,20 @@ pygame.init()
screenW = 561 screenW = 561
screenH = 325 screenH = 325
screen = pygame.display.set_mode((screenW, screenH)) screen = pygame.display.set_mode((screenW, screenH))
knob1 = Knob(screen)
knobs_radius = screenW / 25
knobs_spacing = knobs_radius * 2
knobs_x = (screenW - (knobs_radius + knobs_spacing) * 2) / 2
x = knobs_x
knobs_y = (screenH - (knobs_radius + knobs_spacing) * 3) / 2
y = knobs_y
knobs = []
for i in range(8):
knobs.append(Knob(screen, (0, 210, 200), knobs_radius, (x, y)))
y += knobs_radius + knobs_spacing
if i == 3 or i == 6:
x += knobs_radius + knobs_spacing
y = knobs_y
clock = pygame.time.Clock() clock = pygame.time.Clock()
running = True running = True
@ -22,8 +35,10 @@ while running:
screen.fill("black") screen.fill("black")
# RENDER YOUR GAME HERE # RENDER YOUR GAME HERE
knob1.display() for i in range(8):
knobs[i].display()
pygame.draw.polygon(screen, "white", [(0, screenH/2), (screenW*3/19, screenH), (0, screenH)])
# flip() the display to put your work on screen # flip() the display to put your work on screen
pygame.display.flip() pygame.display.flip()