Hardware Reference
In-Depth Information
Listing 15-4 continued
sys.exit()
def checkForQuit():
global col, picture, last_reading, fileName
event = pygame.event.poll()
if event.type == pygame.QUIT :
terminate()
elif event.type == pygame.KEYDOWN :
# get a key and do something
if event.key == pygame.K_ESCAPE :
terminate()
if event.key == K_SPACE or event.key == K_DELETE:
blank_screen()
if event.key == K_r : # draw in red
col = (255, 0, 0)
if event.key == K_g : # draw in green
col = (0, 255, 0)
if event.key == K_b : # draw in blue
col = (0, 0, 255)
if event.key == K_y : # draw in yellow
col = (255, 255, 0)
if event.key == K_m : # draw in magenta
col = (255, 0, 255)
if event.key == K_p : # draw in peacock blue
col = (0, 255, 255)
if event.key == K_w : # draw in white
col = (255, 255, 255)
if event.key == K_k : # draw in blacK
col = (0, 0, 0)
if event.key == K_s : # save current point
last_reading[2] = last_reading[0] # save X
last_reading[3] = last_reading[1] # save Y
if event.key == K_l : # draw a line to saved point
pygame.draw.line(screen,col,(last_reading[2],;
last_reading[3]),(last_reading[0],last_reading[1]),2)
pygame.display.update()
if event.key == K_c : # draw a circle
try :
r = ((last_reading[0] - last_reading[2])**2 ;
+ (last_reading[1] - last_reading[3])**2 ) ** (0.5)
pygame.draw.circle(screen,col,;
(last_reading[0],last_reading[1]),int(r),2)
Search WWH ::




Custom Search