improved the design of the knob component

This commit is contained in:
SallarShayegan
2025-02-23 20:10:03 +01:00
parent 9276965f7b
commit e80152716b
2 changed files with 4 additions and 6 deletions

View File

@ -6,16 +6,16 @@ class Knob:
def __init__(self, screen): def __init__(self, screen):
self.screen = screen self.screen = screen
self.radius = screen.get_width()/20 self.radius = screen.get_width()/20
self.fill_color = (255,0,255) self.fill_color = (160,0,255)
self.position = (screen.get_width()/2, screen.get_height()/2) self.position = (screen.get_width()/2, screen.get_height()/2)
self.value = 0.1 self.value = 0
def set_value(self, value): def set_value(self, value):
self.value = value self.value = value
def get_pointer_position(self): def get_pointer_position(self):
x = self.radius * math.cos((self.value * 2 + 0.5) * math.pi) + self.position[0] x = self.radius * math.cos((self.value * 0.8 * 2 + 0.7) * math.pi) + self.position[0]
y = self.radius * math.sin((self.value * 2 + 0.5) * math.pi) + self.position[1] y = self.radius * math.sin((self.value * 0.8 * 2 + 0.7) * math.pi) + self.position[1]
return(x, y) return(x, y)
def display(self): def display(self):

View File

@ -1,4 +1,3 @@
# Example file showing a basic pygame "game loop"
import pygame import pygame
from knob import * from knob import *
@ -25,7 +24,6 @@ while running:
# RENDER YOUR GAME HERE # RENDER YOUR GAME HERE
knob1.display() knob1.display()
# flip() the display to put your work on screen # flip() the display to put your work on screen
pygame.display.flip() pygame.display.flip()