- muster.py
# -*- coding: utf-8 -*-
"""
pygame step003
static blitting of ball surface
url: http://thepythongamebook.com/en:part2:pygame:step003
author: horst.jens@spielend-programmieren.at
Blitting a surface on a static position
Drawing a filled circle into ballsurface.
Blitting this surface once.
introducing pygame draw methods
The ball's rectangular surface is black because the background
color of the ball's surface was never defined nor filled."""
import pygame
pygame.init()
screen=pygame.display.set_mode((480,480))
background = pygame.Surface(screen.get_size())
background.fill((255,255,255)) # fill the background white (red,green,blue)
background = background.convert() # faster blitting
pygame.draw.line(background,(0,0,0),(0,480),(0,0),1)
for z in range(0,481,3):
x1=0
y1=480-z
y2=0
x2=z
pygame.draw.line(background,(z/1.8759,z/2,0),(x1,y1),(x2,y2),1)
pygame.draw.line(background,(0,0,0),(0,480),(480,480),1)
for z in range(0,481,2):
x1=z
y1=480
y2=480-z
x2=480
pygame.draw.line(background,(z/2,0,z/1.8759),(x1,y1),(x2,y2),1)
#------- blit the surfaces on the screen to may1ke them visible
screen.blit(background, (0,0)) # blit the background on the screen (overwriting all)
#screen.blit(ballsurface, (ballx, bally)) # blit the topleft corner of ball surface at pos (ballx, bally)
clock = pygame.time.Clock()
mainloop = True
FPS = 30 # desired framerate in frames per second. try out other values !
playtime = 0.0
while mainloop:
milliseconds = clock.tick(FPS) # do not go faster than this frame rate
playtime += milliseconds / 1000.0
# ----- event handler -----
for event in pygame.event.get():
if event.type == pygame.QUIT:
mainloop = False # pygame window closed by user
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
mainloop = False # user pressed ESC
pygame.display.set_caption("Frame rate: %.2f frames per second. Playtime: %.2f seconds" % (clock.get_fps(),playtime))
pygame.display.flip() # flip the screen like in a flipbook
print "this 'game' was played for %.2f seconds" % playtime
orzeasy9stephan.py
de/personen/stephan/start.txt · Zuletzt geändert: 2011/02/17 12:50 von stephan