pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Wiki

RotateCenter

      
Search:  
 
 

Rotate while keeping an image's center and size. I had to solve this for Trolls Outta Luckland, which needed to rotate an arbitrary image without jittering, resizing, or needing a new hitmask for each rotation. It *only* works with square images.

def rot_center(image, angle):
    """rotate an image while keeping its center and size"""
    orig_rect = image.get_rect()
    rot_image = pygame.transform.rotate(image, angle)
    rot_rect = orig_rect.copy()
    rot_rect.center = rot_image.get_rect().center
    rot_image = rot_image.subsurface(rot_rect).copy()
    return rot_image

This one works with images of any dimension, but does not keep the image's original shape (retaining the original shape could truncate the image).

def rot_center(image, rect, angle):
        """rotate an image while keeping its center"""
        rot_image = pygame.transform.rotate(image, angle)
        rot_rect = rot_image.get_rect(center=rect.center)
        return rot_image,rot_rect
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Apr 25, 2014

Apr 21, 2014


Apr 19, 2014

Apr 16, 2014

Apr 13, 2014

Apr 9, 2014

Mar 18, 2014


Mar 15, 2014

Mar 14, 2014

Mar 13, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)