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
Jan 24, 2015

Jan 20, 2015



Jan 15, 2015

Jan 14, 2015


Jan 7, 2015

Jan 4, 2015


Dec 30, 2014

Dec 14, 2014

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