[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] Making a clock rotate



Hi all, I'm trying to make a clock with pygame and python2.2 but I have a
problem in rotating the pointer.
The image is the pointer, and quadrante is the clock. The code below is
just supposed to rotate of 6 degrees CW the pointer but I don't manage
to...
I've also tried without the class using a main() and an update() functions
to create and manage the clock, but either way it doesn't work...
where am I mistaken?

class orologio:
def __init__(self):
self.quadrante = pygame.display.set_mode((256,256))
self.image = pygame.image.load('~/Documents/lancetta.jpg')
self.image = self.image.convert()
self.axis = (128,128)
self.quadrante.blit(self.image, [126,0])
pygame.display.flip()
self.second_degree = -6
self.quadrante = rotate_with_axis(self.quadrante, self.second_degree, \
self.axis)
self.quadrante.blit(self.quadrante, self.quadrante.get_rect())
pygame.display.flip()

def rotate_with_axis(surf,angle,axis):
"""rotates image by angle degrees CCW, and returns a surface the
same size as the input image.

new pixels may be visible in the result that weren't in the
original image. see
http://www.pygame.org/docs/ref/pygame_transform.html#rotate for
the rules about those"""

# make a bigger surface padded such that the axis point is in the center
paddedsize=[max(anaxis,asize-anaxis)*2 for anaxis,asize in \
zip(axis,surf.get_size())]
padded=pygame.Surface(paddedsize,0,surf)
padded.blit(surf,[ps//2-a for ps,a in zip(paddedsize,axis)])
# rotate the big image
rotated=pygame.transform.rotate(padded,angle)
# cut out the appropriate piece of the larger rotated image
newtopcorner=[rs//2-a for rs,a in zip(rotated.get_size(),axis)]
return rotated.subsurface(pygame.Rect(newtopcorner+list(surf.get_size())))

if __name__=='__main__':
pygame.init()
clock = orologio()
time.sleep(10)

--
try: troll.uses(Brain)
except TypeError, data: troll.plonk()
Co-Responsabile Hardware Information & Technology http://hit.edengames.net