-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
230 lines (179 loc) · 9.15 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# draw mouse trail
import pygame
import math
# WINDOW = pygame.display.set_mode((1920, 1080), pygame.RESIZABLE) # STILL IN TESTING
WINDOW = pygame.display.set_mode((500, 450))
PREVIOUS_SIZE = 0
PREVIOUS_INDEX = 0
running = 1
BLUE_TRAIL = []
RED_TRAIL = []
GREEN_TRAIL = []
YELLOW_TRAIL = []
MAGENTA_TRAIL = []
ORANGE_TRAIL = []
paint_mode = 1
index = paint_mode - 1
paint_color = (255, 255, 255)
X_DIM_IMAGE = pygame.image.load("x_hover.png")
X_DIM_IMAGE = pygame.transform.scale(X_DIM_IMAGE, (40, 40))
X_HOVER_IMAGE = pygame.image.load("x_dim.png")
X_HOVER_IMAGE = pygame.transform.scale(X_HOVER_IMAGE, (40, 40))
paint = True
paint_still = False
pygame.display.set_caption("PyPaint v1.0")
while running:
pygame.draw.rect(WINDOW, (50, 40, 40), (0, 0, 40, 450))
pygame.draw.rect(WINDOW, (255, 0, 0), (0, 20, 40, 40))
pygame.draw.rect(WINDOW, (0, 255, 0), (0, 70, 40, 40))
pygame.draw.rect(WINDOW, (0, 100, 200), (0, 120, 40, 40))
pygame.draw.rect(WINDOW, (255, 255, 0), (0, 170, 40, 40))
pygame.draw.rect(WINDOW, (128, 0, 128), (0, 220, 40, 40))
pygame.draw.rect(WINDOW, (255, 69, 0), (0, 270, 40, 40))
WINDOW.blit(X_HOVER_IMAGE, (-2, 400))
def draw_trail(color):
for line in BLUE_TRAIL:
pygame.draw.circle(WINDOW, color, (line[0], line[1]), paint_mode, index)
for line in RED_TRAIL:
pygame.draw.circle(WINDOW, color, (line[0], line[1]), paint_mode, index)
for line in GREEN_TRAIL:
pygame.draw.circle(WINDOW, color, (line[0], line[1]), paint_mode, index)
def clearTrails():
BLUE_TRAIL.clear()
RED_TRAIL.clear()
GREEN_TRAIL.clear()
YELLOW_TRAIL.clear()
MAGENTA_TRAIL.clear()
ORANGE_TRAIL.clear()
for event in pygame.event.get():
key = pygame.key.get_pressed()
if event.type == pygame.QUIT:
pygame.quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_EQUALS:
paint_mode += 2
print(paint_mode)
elif event.key == pygame.K_MINUS:
# print(paint_color)
if not index >= paint_mode:
#print("Index is not less than paint mode")
print(index)
if index >= 0:
print(index)
# PREVIOUS_INDEX = index
# PREVIOUS_SIZE = paint_mode
if index == 0:
paint_mode = 2
else:
paint_mode = paint_mode-1
index = index-1
elif event.key == pygame.K_ESCAPE:
pygame.quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if pygame.mouse.get_pos()[0] in range(7, 29) and pygame.mouse.get_pos()[1] in range(400, 436):
clearTrails()
WINDOW.fill((0, 0, 0))
pygame.draw.rect(WINDOW, (50, 40, 40), (0, 0, 40, 450))
pygame.draw.rect(WINDOW, (255, 0, 0), (0, 20, 40, 40))
pygame.draw.rect(WINDOW, (0, 255, 0), (0, 70, 40, 40))
pygame.draw.rect(WINDOW, (0, 100, 200), (0, 120, 40, 40))
pygame.draw.rect(WINDOW, (255, 255, 0), (0, 170, 40, 40))
pygame.draw.rect(WINDOW, (128, 0, 128), (0, 220, 40, 40))
pygame.draw.rect(WINDOW, (255, 69, 0), (0, 270, 40, 40))
if pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(
0, 450):
clearTrails()
draw_trail((255, 0, 0)) # default
print(paint_color)
paint = False
if pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(
20, 60):
clearTrails()
draw_trail((255, 0, 0))
paint_color = (255, 0, 0)
print(paint_color)
paint = True
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(
70, 110):
clearTrails()
draw_trail((0, 255, 0))
paint_color = (0, 255, 0)
print(paint_color)
paint = True
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(
120, 160):
clearTrails()
draw_trail((0, 100, 200))
paint_color = (0, 100, 200)
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(
170, 210):
clearTrails()
draw_trail((255, 255, 0))
paint_color = (255, 255, 0)
print(paint_color)
paint = True
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(
220, 270):
clearTrails()
draw_trail((128, 0, 128))
paint_color = (128, 0, 128)
print(paint_color)
paint = True
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(170, 320):
clearTrails()
draw_trail((255, 69, 0))
paint_color = (255, 69, 0)
print(paint_color)
paint = True
else:
if not paint_still:
# IF MOUSE NOT MOVING BUT STILL ON CANVAS INCREASE SIZE SO IS VISIBLE
draw_trail(paint_color)
paint_still = True
pygame.display.update()
elif event.type == pygame.MOUSEMOTION:
print(pygame.mouse.get_pos())
if pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(0, 450):
paint = False
if pygame.mouse.get_pos()[0] in range(7, 29) and pygame.mouse.get_pos()[1] in range(400, 436):
WINDOW.blit(X_DIM_IMAGE, (-2, 400))
if pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(120, 160):
pygame.draw.rect(WINDOW, (255, 0, 0), (0, 20, 40, 40))
pygame.draw.rect(WINDOW, (0, 255, 0), (0, 70, 40, 40))
pygame.draw.rect(WINDOW, (0, 0, 255), (0, 120, 40, 40))
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(20, 60):
pygame.draw.rect(WINDOW, (100, 0, 0), (0, 20, 40, 40))
pygame.draw.rect(WINDOW, (0, 255, 0), (0, 70, 40, 40))
pygame.draw.rect(WINDOW, (0, 100, 200), (0, 120, 40, 40))
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(70, 110):
pygame.draw.rect(WINDOW, (255, 0, 0), (0, 20, 40, 40))
pygame.draw.rect(WINDOW, (0, 100, 0), (0, 70, 40, 40))
pygame.draw.rect(WINDOW, (0, 100, 200), (0, 120, 40, 40))
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(170, 210):
pygame.draw.rect(WINDOW, (255, 0, 0), (0, 20, 40, 40))
pygame.draw.rect(WINDOW, (0, 255, 0), (0, 70, 40, 40))
pygame.draw.rect(WINDOW, (0, 100, 200), (0, 120, 40, 40))
pygame.draw.rect(WINDOW, (150, 150, 0), (0, 170, 40, 40))
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(220, 261):
pygame.draw.rect(WINDOW, (255, 0, 0), (0, 20, 40, 40))
pygame.draw.rect(WINDOW, (0, 255, 0), (0, 70, 40, 40))
pygame.draw.rect(WINDOW, (0, 100, 200), (0, 120, 40, 40))
pygame.draw.rect(WINDOW, (255, 255, 0), (0, 170, 40, 40))
pygame.draw.rect(WINDOW, (80, 0, 80), (0, 220, 40, 40))
elif pygame.mouse.get_pos()[0] in range(0, 40) and pygame.mouse.get_pos()[1] in range(270, 310):
pygame.draw.rect(WINDOW, (255, 0, 0), (0, 20, 40, 40))
pygame.draw.rect(WINDOW, (0, 255, 0), (0, 70, 40, 40))
pygame.draw.rect(WINDOW, (0, 100, 200), (0, 120, 40, 40))
pygame.draw.rect(WINDOW, (255, 255, 0), (0, 170, 40, 40))
pygame.draw.rect(WINDOW, (128, 0, 128), (0, 220, 40, 40))
pygame.draw.rect(WINDOW, (100, 40, 0), (0, 270, 40, 40))
else:
paint = True
if paint:
if pygame.mouse.get_pressed()[0]:
pi = math.pi
x, y = pygame.mouse.get_pos()
# PREVIOUS_INDEX, PREVIOUS_SIZE = index, paint_mode
pygame.draw.circle(WINDOW, paint_color, (x, y), paint_mode, index)
pygame.display.update()
pygame.display.update()