-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeth.py
96 lines (85 loc) · 3.07 KB
/
meth.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/path/to/venv/bin/python
import sys, os
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide"
import pygame
from datetime import datetime
from PIL import Image
# Constants (edit these to your liking)
SCREENSHOTS = '/home/tox/Math/METH/screenshots'
WIDTH = 800
HEIGHT = 600
BLACK = (30, 30, 46)
WHITE = (205, 214, 244)
PINK = (245, 194, 231)
YELLOW = (249, 226, 175)
RED = (243, 139, 168)
BLUE = (137, 180, 250)
GREEN = (166, 227, 161)
def main():
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.RESIZABLE)
pygame.display.set_caption("Meth - a simple drawing program")
canvas = pygame.Surface((WIDTH, HEIGHT))
canvas.fill(BLACK)
draw_radius = 2.5
erase_radius = 10
selected_color = WHITE
drawing = False
erasing = False
clock = pygame.time.Clock()
resize_flag = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1: # LMB
drawing = True
elif event.button == 3: # RMB
erasing = True
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
drawing = False
elif event.button == 3:
erasing = False
elif event.type == pygame.MOUSEMOTION:
if drawing:
pygame.draw.circle(canvas, selected_color, event.pos, draw_radius)
elif erasing:
pygame.draw.circle(canvas, BLACK, event.pos, erase_radius)
elif event.type == pygame.KEYDOWN:
match event.key:
case pygame.K_c:
canvas.fill(BLACK)
case pygame.K_s:
imgpath = os.path.join(SCREENSHOTS, f"DRAW-{datetime.now()}.png")
pygame.image.save(canvas, imgpath)
case pygame.K_p:
selected_color = PINK
case pygame.K_y:
selected_color = YELLOW
case pygame.K_r:
selected_color = RED
case pygame.K_g:
selected_color = GREEN
case pygame.K_b:
selected_color = BLUE
case pygame.K_w:
selected_color = WHITE
elif event.type == pygame.VIDEORESIZE:
resize_flag = True
if resize_flag:
new_width, new_height = pygame.display.get_surface().get_size()
new_canvas = pygame.Surface((new_width, new_height))
new_canvas.fill(BLACK)
new_canvas.blit(canvas, (0, 0))
canvas = new_canvas
pygame.display.flip()
resize_flag = False
screen.fill(BLACK)
screen.blit(canvas, (0, 0))
pygame.display.flip()
clock.tick(300)
if __name__ == "__main__":
main()