Changed how the spinner is rendered
This commit is contained in:
18
game.py
18
game.py
@ -76,7 +76,7 @@ class Game(gameUtils.Game):
|
||||
|
||||
font = pygame.font.SysFont('', 32)
|
||||
|
||||
items = [f'Example item {i+1}' for i in range(17)]
|
||||
self.items = [f'Example item {i+1}' for i in range(13)]
|
||||
# How many pixels away from the outer side of the
|
||||
# circle the text should be
|
||||
textMargin = 5
|
||||
@ -86,13 +86,17 @@ class Game(gameUtils.Game):
|
||||
# Draw the base circle
|
||||
pygame.draw.circle(self.wheelSurf, (25, 25, 25), (circleR, circleR), circleR)
|
||||
# Calculate the gap, in radians, between each item
|
||||
gap = maths.pi * 2 / len(items)
|
||||
gap = maths.pi * 2 / len(self.items)
|
||||
|
||||
for idx, item in enumerate(items):
|
||||
for idx, item in enumerate(self.items):
|
||||
# Calculate the radians of this item
|
||||
rad = (idx / len(items)) * maths.pi * 2
|
||||
# Calculate the vector from that
|
||||
vector = maths.cos(rad), maths.sin(rad)
|
||||
rad = (idx / len(self.items)) * maths.pi * 2
|
||||
# Rotate it CCW be 90deg so the first item is on the top
|
||||
rad -= maths.pi / 2
|
||||
# Calculate the vector offset by half the item gap
|
||||
# This is because the text should be in the middle,
|
||||
# and the lines (which is what this is used by) on the edges
|
||||
vector = maths.cos(rad+gap/2), maths.sin(rad+gap/2)
|
||||
# Calculate the end position of a line based on the vector
|
||||
endPos = np.add(np.multiply(vector, circleR), circleR)
|
||||
# Draw the dividing line
|
||||
@ -109,7 +113,7 @@ class Game(gameUtils.Game):
|
||||
#pygame.draw.line(textSurf, (255, 0, 0), (circleR, circleR), (textSurf.size[0], circleR))
|
||||
#pygame.draw.line(textSurf, (0, 255, 0), (circleR, circleR), (circleR, textSurf.size[1]))
|
||||
# Rotate the text surface
|
||||
textSurf = rotateRad(textSurf, rad+gap/2)
|
||||
textSurf = rotateRad(textSurf, rad)
|
||||
# Blit the text surface to the wheel surface
|
||||
self.wheelSurf.blit(textSurf, (0, 0))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user