-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtracersystem.py
36 lines (33 loc) · 1.05 KB
/
tracersystem.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
import pygame
from sys import exit
from PIL import Image
from settings import *
def getEvents(screen, trace):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit(0)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
retrace(screen, trace)
return True
if event.key == pygame.K_F12:
saveimg(image)
def saveimg(image):
path = os.getenv("USERPROFILE") + "\\Pictures\\pytracer\\"
if os.path.isdir(path):
dirs = list()
for i in os.listdir(path):
current = i[:i.rfind(".")]
if i[i.rfind(".") + 1:] == "png" and\
current.isdigit():
dirs.append(int(current))
dirs.sort()
image.save(path + f"{dirs[-1] + 1}.png")
else:
os.makedirs(path)
image.save(path + "1.png")
def retrace(screen, trace):
screen.fill(BACKGROUND_COLOR)
trace(screen)
pygame.display.flip()