view 000/004.py @ 12:9dc97f88e274 default tip

Added CC0 license
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sun, 08 Jul 2012 19:56:38 +0200
parents ee28ba29d97e
children
line wrap: on
line source

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygame
import pygame.locals as pg


def initialize_screen():
    """Initialize pygame, create a window and fill it with gray.
    Return the screen surface.
    """
    pygame.display.init()
    screen = pygame.display.set_mode((800, 600))
    screen.fill((0x66, 0x66, 0x66))
    return screen

def load_and_display_image(screen):
    """Load the image and display it in the middle of the screen."""
    image = pygame.image.load('cup.png')
    image = image.convert()
    image.set_colorkey((0xff, 0x00, 0xff))
    screen_rect = screen.get_rect()
    image_rect = image.get_rect()
    screen.blit(image, (
            (screen_rect.width - image_rect.width) // 2,
            (screen_rect.height - image_rect.height) // 2,
        )
    )

def wait_for_quit():
    """Sit there doing nothing until the window is closed."""
    clock = pygame.time.Clock()
    pygame.display.update()
    while True:
        event = pygame.event.wait()
        if event.type == pg.QUIT:
            return
        clock.tick(60)


if __name__ == '__main__':
    screen = initialize_screen()
    load_and_display_image(screen)
    wait_for_quit()