I am trying to rotate an element (in my case font) in pygame around a pivot point my code is as follows:
import pygame, time
pygame.init()
display_width = 800
display_height = 800
window = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("Dials")
black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
clock = pygame.time.Clock()
font = pygame.font.SysFont('Arial', 50, True)
#All Images of Dials
tutorial = [pygame.image.load('Dial_Images/tutorial_base.png')]
tutorialInputs = [[1,4,3,4], [1,4,3,2], [1,4,3,2], [1,4,3,4]]
class Dial:
def __init__(self, x, y, radius, inputs):
self.x = x
self.y = y
self.radius = radius
self.inputs = inputs
self.columns = len(self.inputs)
self.rows = len(self.inputs[0])
def drawDial(self):
for i in range(0, self.columns):
pygame.draw.circle(window, red, (self.x, self.y), self.radius)
pygame.draw.circle(window, black, (self.x, self.y), self.radius, 1)
if self.rows == 4:
input_1 = font.render(str(self.inputs[0][0]), 1, black)
input_2 = font.render(str(self.inputs[0][1]), 1, black)
input_3 = font.render(str(self.inputs[0][2]), 1, black)
input_4 = font.render(str(self.inputs[0][3]), 1, black)
window.blit(input_1, (self.x - 4, self.y - self.radius + 10))
window.blit(input_2, (self.x + self.radius - 35, self.y - 15))
window.blit(input_3, (self.x - 4, self.y + self.radius - 40))
window.blit(input_4, (self.x - self.radius + 20, self.y - 15))
def level_1():
window.fill(white)
dial1.drawDial()
#all Dials Instantiated
dial1 = Dial(int(display_width/2), int(display_height/2), int((display_width/2) - 100), tutorialInputs)
score = 0
run = True
level1 = True
while run:
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.update()
clock.tick(100)
if level1:
level_1()
pygame.quit()
The following will create a window and a circle with a black border and 4 numbers at 12 o'clock, 3 o'clock, 6 o'clock and 9 o'clock.
I want to rotate the inputs around the center of the circle. Any pygame function that will allow me to rotate input_1 - input _4 90 degrees around the center of the circle? I saw on pygame some functions like pygame.math.vector and some other .rotate function, but I wanted the best approach.
Also, if there is a way to clean up the way I code the location of the inputs so that they align at 12 o'clock, 3 o'clock, 6 o'clock and 9 o'clock that would be helpful.