-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-1.py
50 lines (40 loc) · 1.28 KB
/
demo-1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/python
import pygame
import os
import sys
def load_image(filename):
return pygame.image.load(filename)
def save_image(image, filename):
pygame.image.save(image, filename)
def main():
in_filename = "background.png"
if len(sys.argv) > 1:
in_filename = sys.argv[1]
out_filename = "background.png"
if len(sys.argv) > 2:
out_filename = sys.argv[2]
screen = pygame.display.set_mode((800, 600))
if os.path.isfile(in_filename):
image = load_image(in_filename)
xformed = pygame.transform.scale(image, screen.get_size())
screen.blit(xformed, (0, 0))
running = True
drawing = False
last_pos = None
while running:
for e in pygame.event.get():
if e.type == pygame.QUIT:
running = False
elif e.type == pygame.MOUSEBUTTONDOWN:
last_pos = e.pos
drawing = True
elif e.type == pygame.MOUSEBUTTONUP:
drawing = False
if drawing:
cur_pos = pygame.mouse.get_pos()
pygame.draw.line(screen, (255, 0, 0), last_pos, cur_pos, 2)
last_pos = cur_pos
pygame.display.update()
save_image(screen, out_filename)
if __name__ == '__main__':
main()