I have a python script to simulate a wrench moving, I have calculated it's origins position in x and y as a function of time, the problem is when I try to rotate the image, my code moves the image out of frame.
import pygame, sys
import math
screen = pygame.display.set_mode((700, 400))
wrench = pygame.image.load('prueba.bmp')
white = (255,255,255)
ox = 20
oy = 32
running = True
posX = 100 - ox
posY = 100 - oy
pygame.init()
while running:
event = pygame.event.poll()
if event.type == pygame.QUIT:
running=0
screen.blit(wrench, (posX, posY))
if(pygame.time.get_ticks() <= 20000):
screen.fill(white)
t = pygame.time.get_ticks() / 1000
print(t)
ang = math.degrees((math.pi / 2 * math.cos(math.pi * t)))
posX = 100 + (50 * math.cos(math.pi * t)) - ox
posY = 100 + (20 * math.sin(math.pi * t)) - oy
wrench = pygame.transform.rotate(wrench, ang)
screen.blit(wrench, (posX, posY))
pygame.display.flip()
Does anybody knows why this is happening?