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

Jun 23, 2015

Jun 21, 2015

Jun 17, 2015

Jun 14, 2015

Jun 8, 2015

Jun 7, 2015

May 31, 2015

May 28, 2015

May 18, 2015

May 7, 2015


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