-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyPaint V0.0.08.py
405 lines (334 loc) · 11.3 KB
/
PyPaint V0.0.08.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
import pygame
import os
import time
import webbrowser
pygame.init()
"""
################################################
add a list of shortcuts to the screen on startup
################################################
#file name input option?
webbrowser.open("filename")
works perfectly.
#show list of files, then selecting a pens it
Allow name of file, since this is PyPaint, link it
the PyNotes Main Program.
separate the folder which each file is saved by
the current date(first 5 or so characters)
ascii to paint
use ascii art to draw pixel and color at specific point.
needs to do text box.. badly
cursor = pygame.cursors.compile(pygame.cursors.textmarker_strings)
pygame.mouse.set_cursor(*cursor)
eliminated dot at text when reclicking
#######
IDEA!!!
Instead of putting screen blits into a list, just do it once
IDEA!!!
#######
compile(strings, black=’ ’, white=’.’, or=’o’)
thickarrow_strings = ( #sized 24 24
" ",
" ",
" ",
" . ",
" .. ",
" ... ",
" .... ",
" ..... ",
" ...... ",
" ....... ",
" ........ ",
" ........ ",
" ...... ",
" . .. ",
" .. ",
" .. ",
" .. ",
" .. ",
" .. ",
" ",
" ",
" ",
" ",
" ")
Eraser_strings = ( #sized 32x32
" ",
" ",
" ",
" ",
" .... ",
" ........ ",
" ...XXXXXX... ",
" ...XXXXXXXXXX... ",
" ..XXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXX.. ",
" ...XXXXXXXXXX... ",
" ...XXXXXX... ",
" ........ ",
" .... ",
" ",
" ",
" ",
" ",
" ",
" ")
"""
def UFL(folder="Files\\Paint"):
global files
files = list()
cwd = os.getcwd()
path = os.path.join(cwd, folder)
print("------------FILES------------")
for c in os.walk(path).__next__()[2]:
print(c)
files.append(c)
##def load():
## UFL()
## global dots
## dots = list()
## print("Do you want to open a saved file(yes/no)?")
## LOAD = input()
## if LOAD == 'yes' or LOAD == 'y':
## for f in files:
## print(f)
## file = input('filename: ')
## FileName = 'Files/Paint'+file+'.t t'
## with open(FileName, 'r') as f:
## for line in f:
## a = line[0:4]
## b = line[4:9] #line[-9:-3]
## if len(a) == 2:
## a = '0'+a
## if len(a) == 1:
## a = '00'+a
## inta = int(a)
## intb = int(b)
## coords = [inta, intb]
## #print(coords)
## dots.append(coords)
## f.close()
# Window
SIZE = (900, 600)
TITLE = "Paint"
screen = pygame.display.set_mode(SIZE)
pygame.display.set_caption(TITLE)
# Timer
clock = pygame.time.Clock()
refresh_rate = 500 #250
# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
current_color = RED
# Brush
radius = 5;
SIZE1 = 1
SIZE2 = 2
SIZE3 = 3
SIZE4 = 4
SIZE5 = 5
SIZE6 = 6
SIZE7 = 7
SIZE8 = 8
SIZE9 = 9
SIZE = 5
Eraser_strings = ( #sized 32x32
" ",
" ",
" ",
" ",
" ",
" ........ ",
" ...XXXXXX... ",
" ...XXXXXXXXXX... ",
" ..XXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXXXX.. ",
" ..XXXXXXXXXXXXXX.. ",
" ...XXXXXXXXXX... ",
" ...XXXXXX... ",
" ........ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ")
# Cursor
original_cursor = pygame.mouse.get_cursor()
cursor = pygame.cursors.compile(Eraser_strings)
##cursor_vars = ((32,32),(16,16),*cursor)
pygame.mouse.set_cursor((32,32),(16,16),*cursor)
# Palete Location
RED_BOX = (10, 560, 30, 30)
GREEN_BOX = (50, 560, 30, 30)
BLUE_BOX = (90, 560, 30, 30)
# Text Box
text_boxes=[]
# Game loop
done = False
saving = False
textbox = False
text_click=False
while not done:
## cursor = pygame.cursors.compile(Eraser_strings)
## pygame.mouse.set_cursor((32,32),(16,16),*cursor)
# Event processing (React to key presses, mouse clicks, etc.)
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
SIZE = SIZE1
if event.key == pygame.K_2:
SIZE = SIZE2
if event.key == pygame.K_3:
SIZE = SIZE3
if event.key == pygame.K_4:
SIZE = SIZE4
if event.key == pygame.K_5:
SIZE = SIZE5
if event.key == pygame.K_6:
SIZE = SIZE6
if event.key == pygame.K_7:
SIZE = SIZE7
if event.key == pygame.K_8:
SIZE = SIZE8
if event.key == pygame.K_9:
SIZE = SIZE9
if event.key == pygame.K_0:
screen.fill(BLACK)
#reset variables
text_boxes=[]
SIZE = SIZE5
color = RED
if event.key == pygame.K_s:
if not saving:
saving = True
if event.key == pygame.K_e:
SIZE=SIZE9
current_color=BLACK
#make black color, as well as erase cursor
if event.key == pygame.K_t:
if not textbox and not text_click:
textbox = True
# Game logic
if saving:
## name = ''
name = input('input filename: ')
#if day is single digit, change it to 0[digit]
daystr=time.asctime()[8:10]
if time.asctime()[8]==' ':
daystr='0'+time.asctime()[9]
time_string = str(time.asctime()[4:7]+\
daystr+\
time.asctime()[11:13]+\
time.asctime()[14:16]+\
time.asctime()[17:19])
pygame.image.save(screen,
"Files//PAINT//"+\
time_string+\
"_"+name+\
".jpeg")
saving = not saving
print('-----SAVED IMAGE-----')
print(time_string+"_"+name+".jpeg")
print('---------------------')
if not textbox:
pygame.draw.rect(screen,BLACK,(130,560,30,30))
if textbox:
#change mouse?
pygame.draw.rect(screen,WHITE,(130,560,30,30))
print('\n\n\n\n\n')
print('-----------')
t_text = input('input text: ')
print('click position')
print('\n\n\n')
text_click=True
textbox=False
clicks = pygame.mouse.get_pressed()
if clicks[0]:
click_pos = pygame.mouse.get_pos()
x = click_pos[0]
y = click_pos[1]
#text click
if text_click:
#return mouse?
tbox_pos=[x,y]
tbox_col=current_color
tbox_text=t_text
#play with multiplier/additive
tbox_size=(SIZE*5)+10
text_boxes.append({'pos':tbox_pos,
'col':tbox_col,
'text':tbox_text,
'size':tbox_size})
pygame.draw.rect(screen,WHITE,(x,y,2,2))
text_click=text_click
#still not erasing
for tb in text_boxes:
font=pygame.font.Font(None,tb['size'])
text=font.render(tb['text'],True,tb['col'])
screen.blit(text,tb['pos'])
## dots.append({'x': x, 'y': y, 'color': current_color})
## print('click!', x, y)
if RED_BOX[0] < x < RED_BOX[0] + RED_BOX[2] and \
RED_BOX[1] < y < RED_BOX[1] + RED_BOX[3]:
current_color = RED
## print('Red')
elif GREEN_BOX[0] < x < GREEN_BOX[0] + GREEN_BOX[2] and \
GREEN_BOX[1] < y < GREEN_BOX[1] + GREEN_BOX[3]:
current_color = GREEN
## print('Green')
elif BLUE_BOX[0] < x < BLUE_BOX[0] + BLUE_BOX[2] and \
BLUE_BOX[1] < y < BLUE_BOX[1] + BLUE_BOX[3]:
current_color = BLUE
## print('Blue')
else:
## print('draw')
if not text_click:
pygame.draw.circle(screen, current_color, [x, y], SIZE)
#This prevents a dot from appearing when text click
text_click=False
''' draw palette '''
pygame.draw.rect(screen, RED, RED_BOX)
pygame.draw.rect(screen, WHITE, RED_BOX, 2)
pygame.draw.rect(screen, GREEN, GREEN_BOX)
pygame.draw.rect(screen, WHITE, GREEN_BOX, 2)
pygame.draw.rect(screen, BLUE, BLUE_BOX)
pygame.draw.rect(screen, WHITE, BLUE_BOX, 2)
## for tb in text_boxes:
## font=pygame.font.Font(None,tb['size'])
## text=font.render(tb['text'],True,tb['col'])
## screen.blit(text,tb['pos'])
# Update screen
pygame.display.flip()
clock.tick(refresh_rate)
# Close window on quit
pygame.quit()