pygame / test_pygame /

#!/usr/bin/env python

'''Check that crop works.

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

import math
import os
import sys

import pygame
from pygame.locals import *

if __name__ == '__main__':

    if len(sys.argv) > 1:
        image_file = sys.argv[1]
        image_file = os.path.join(os.path.dirname(sys.argv[0]), 

    image = pygame.image.load(image_file)
    w, h = image.get_size()

    screen = pygame.display.set_mode((w, h))

    dx = 1
    dy = 1
    x = 0
    y = 0
    view_w = w / 3
    view_h = h / 3
    clock = pygame.time.Clock()
    while True:
        for event in pygame.event.get():
            if event.type in (KEYDOWN, QUIT):

        x += dx
        y += dy
        if x + view_w >= w or x < 0:
            dx = -dx
        if y + view_h >= h or y < 0:
            dy = -dy

        surf = pygame.transform.crop(image, (x, y, view_w, view_h))

        screen.fill((255, 0, 0))
        screen.blit(surf, (x, y))
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
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.