Created
May 4, 2010 03:18
-
-
Save mrluanma/388903 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# a pygame script to draw random size/color rectangle on the screen. | |
# It's adapted from http://apress.com/book/view/9781590598726 chapter 4 | |
import pygame | |
from pygame.locals import * | |
from random import * | |
import sys | |
pygame.init() | |
screen = pygame.display.set_mode((640, 480), FULLSCREEN, 32) | |
clock = pygame.time.Clock() | |
fullscreen = False | |
while True: | |
for event in pygame.event.get(): | |
if event.type == QUIT: | |
sys.exit(0) | |
if event.type == KEYDOWN: | |
if event.key == K_f: | |
fullscreen = not fullscreen | |
if fullscreen: | |
screen = pygame.display.set_mode((640, 480), FULLSCREEN, 32) | |
else: | |
screen = pygame.display.set_mode((640, 480), 0, 32) | |
else: | |
sys.exit(0) | |
clock.tick(30) | |
screen.lock() | |
for count in range(10): | |
random_color = (randint(0, 255), randint(0, 255), randint(0, 255)) | |
random_pos = (randint(0, 639), randint(0, 479)) | |
random_size = (639 - randint(random_pos[0], 639), 479 - randint(random_pos[1], 479)) | |
pygame.draw.rect(screen, random_color, (random_pos, random_size)) | |
screen.unlock() | |
pygame.display.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment