python-examples: c9e27a5a20ee5f3b1c8f1cfb362b33b023e3df64
1: # Mouse-paintable window in 10, 11 and 12 lines
2:
3: import pygame, sys, time
4: # Start the pygame system
5: pygame.init()
6:
7: # This will be our canvas
8: screen = pygame.display.set_mode((800, 600))
9:
10: while True:
11: # Go through pygame's list of accumulated events since the last check
12: for event in pygame.event.get():
13: if event.type == pygame.QUIT: # NOT NEEDED (but makes the close button work)
14: sys.exit() # NOT NEEDED (but makes the close button work)
15: pass # NOT NEEDED (if the above two lines are used)
16: # See if the left mouse button is held down
17: if pygame.mouse.get_pressed()[0]:
18: # Draw a 2 pixel wide white line from the last known position to the current position
19: pygame.draw.line(screen, (255, 255, 255), old_position, pygame.mouse.get_pos(), 2)
20: # Update the window contents
21: pygame.display.update()
22: # Remember the last mouse position
23: old_position = pygame.mouse.get_pos()
24:
25: time.sleep(0.1) # NOT NEEDED (but stops the CPU getting overworked)
26:
Generated by git2html.