-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpygame_example.py
55 lines (49 loc) · 1.66 KB
/
pygame_example.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
51
52
53
54
import io
import pygame
import pygame.font
import time
#import motor_control
def pygame_setup():
pygame.init()
display=pygame.display.set_mode((500,500))
pygame.display.set_caption("DIRECTION CONTROL")
display_font = pygame.font.Font(None, 40)
text = display_font.render('Give Directions Using Arrow Keys', 1,(0,255,255))
text_position = text.get_rect(centerx=250)
display.blit(text,text_position)
pygame.display.update()
def get_directions():
clock=pygame.time.Clock()
try:
while True:
for event in pygame.event.get():
command=""
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_LEFT:
command="LEFT"
if event.key==pygame.K_RIGHT:
command="RIGHT"
if event.key==pygame.K_UP:
command="FORWARD"
if event.key==pygame.K_DOWN:
command="BACK"
elif event.type==pygame.KEYUP:
command="no command"
print(command)
stream = io.BytesIO()
camera.capture(stream, format='jpeg', use_video_port=True)
"""Save image"""
stream.seek(0)
image = Image.open(stream)
image.save("C:/Users/Sanidhya garg/itsp/%s/image%s.jpg" % (command,"-" + command + "-"+ str(time.time())), format="JPEG")
stream.flush()
clock.tick(10)
except KeyboardInterrupt:
pygame.quit()
def main():
"""Main function"""
#motor_contol.gpio_setup()
pygame_setup()
get_directions()
if __name__ == '__main__':
main()