Hardware Reference
In-Depth Information
Listing 5-1 Bounce Test 1
#!/usr/bin/env python
“””
Bounce
A Raspberry Pi test
“””
import time # for delays
import os, pygame, sys
pygame.init() # initialise graphics interface
os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
pygame.display.set_caption(“Bounce”)
screenWidth = 400
screenHeight =400
screen = pygame.display.set_mode([screenWidth,;
screenHeight],0,32)
background = pygame.Surface((screenWidth,screenHeight))
# define the colours to use for the user interface
cBackground =(255,255,255)
cBlock = (0,0,0)
background.fill(cBackground) # make background colour
dx = 5
dy = 10
def main():
X = screenWidth / 2
Y = screenHeight /2
screen.blit(background,[0,0])
while True :
checkForEvent()
#time.sleep(0.05)
drawScreen(X,Y)
X += dx
Y += dy
checkBounds(X,Y)
def checkBounds(px,py):
global dx,dy
if px > screenWidth-10 or px <0:
dx = -dx
if py > screenHeight-10 or py < 0:
dy = - dy
def drawScreen(px,py) : # draw to the screen
Search WWH ::




Custom Search