Hardware Reference
In-Depth Information
Listing 15-4 continued
pygame.init() # initialise pygame
pygame.event.set_allowed(None)
pygame.event.set_allowed([pygame.KEYDOWN, pygame.QUIT,;
pygame.MOUSEBUTTONDOWN])
os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
pygame.display.set_caption(“Roto-Sketch”)
screen = pygame.display.set_mode([512,512],0,32)
lastEncoder = [0,0]
current_reading = [256,256]
last_reading = [256,256,256,256]
# defines initial starting position
col = (0,0,0)
colCursor = (128,128,128)
background = (255, 255, 255) # screen background colour
picture = 1 # picture number
fileName =”name”
lastPort = -1
def main():
global current_reading, last_reading
print “Roto-sketch the keys are:-”
print “R, G, B, Y, M, P, K (black), W to select colour”
print “Space bar for wipe screen”
print “L - for Line to saved point, C for Circle centre on ;
save point”
print “S to save current point for future line and ;
circle commands”
print “Home key to save sketch to file”
print “# to post on Flickr and Facebook”
blank_screen()
while(True): # do forever
readEncoders()
pygame.draw.rect(screen,col,(last_reading[0],;
last_reading[1],2,2),0)
pygame.draw.line(screen,col,(last_reading[0],;
last_reading[1]),(current_reading[0],current_reading[1]),2)
pygame.draw.rect(screen,colCursor,(current_reading[0],;
current_reading[1],2,2),0)
last_reading[0] = current_reading[0]
# save this position for drawing from for next time
last_reading[1] = current_reading[1]
Search WWH ::




Custom Search