pygame / test_pygame / transform_rotate.py

aholkner 651fb9d 
















































#!/usr/bin/env python

'''Check that rotate works.
'''

__docformat__ = 'restructuredtext'
__version__ = '$Id$'

import math
import os
import sys

import pygame
from pygame.locals import *
import Image

if __name__ == '__main__':
    pygame.init()

    if len(sys.argv) > 1:
        image_file = sys.argv[1]
    else:
        image_file = os.path.join(os.path.dirname(sys.argv[0]), 
                                  '../test/sample.bmp')

    image = pygame.image.load(image_file)
    image.set_colorkey(image.get_at((0, 0)))
    #image.set_colorkey((0, 0, 0))
    w, h = image.get_size()

    width = height = int(math.sqrt(w ** 2 + h ** 2))
    screen = pygame.display.set_mode((width, height))

    angle = 0
    clock = pygame.time.Clock()
    while True:
        for event in pygame.event.get():
            if event.type in (KEYDOWN, QUIT):
                sys.exit(0)

        clock.tick(60)
        angle += 1  

        surf = pygame.transform.rotate(image, angle)

        w, h = surf.get_size()
        screen.fill((255, 0, 0))
        screen.blit(surf, (width / 2 - w / 2, height / 2 - h / 2))
        pygame.display.flip()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.