-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
670 lines (588 loc) · 25.9 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
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
#!/usr/bin/python3
import pygame
import pygame.freetype # For text rendering
import sys
import os
import random
import string
import shutil
import subprocess
import math
import zipfile
# Initialize Pygame
pygame.init()
# Constants
CANVAS_WIDTH, CANVAS_HEIGHT = 256, 192
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (232, 51, 48) # E83330
BLUE = (48, 4, 245) # 3004F5
ORANGE = (251, 97, 0) # FB6100
FRAME_COUNTER_COLOR = (255, 82, 0) # FF5200
TOOLBAR_HEIGHT = 70
WINDOW_WIDTH, WINDOW_HEIGHT = CANVAS_WIDTH, CANVAS_HEIGHT + TOOLBAR_HEIGHT
BRUSH_SIZE = 3 # Default draw tool size
UNDO_STACK_SIZE = 10
MAX_FRAMES = 500
DEFAULT_SPEED = 29.9275 # Frames per second
WHITE_BRUSH_SIZE = 8 # Brush size for white color
CURSOR_COLOR = (52, 52, 52) # #343434
MAX_VOLUME = 0.1 # Maximum volume for the drawing sound
DRAW_SOUND = pygame.mixer.Sound("sound/DRAW.wav") # Load the drawing sound
SAVE_SOUND = pygame.mixer.Sound("sound/SAVE.wav") # Load the save sound
OPEN_SOUND = pygame.mixer.Sound("sound/OPEN.wav") # Load the open sound
# Load stuff
info_sound = pygame.mixer.Sound('sound/INFO.wav')
red_button_img = pygame.image.load('assets/red.png')
blue_button_img = pygame.image.load('assets/blue.png')
# Track the last red/blue color used for each frame
last_red_blue_color = RED
# Vars
copied_frame = None # Initialize copied_frame variable
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption('Pynote Studio') # Updated window title
# Load custom font
font_path = 'assets/font.otf' # Make sure the font file is in the same directory
font = pygame.font.Font(font_path, 16) # Reduced font size for "Erase" text
# Load sounds
sounds = {
"OPEN": pygame.mixer.Sound("sound/OPEN.wav"),
"COLOUR": pygame.mixer.Sound("sound/COLOUR.wav"),
"ERASE": pygame.mixer.Sound("sound/ERASE.wav"),
"FRAME_LEFT": pygame.mixer.Sound("sound/FRAME_LEFT.wav"),
"NEW_FRAME": pygame.mixer.Sound("sound/NEW_FRAME.wav"),
"FRAME_RIGHT": pygame.mixer.Sound("sound/FRAME_RIGHT.wav"),
"BLOCK": pygame.mixer.Sound("sound/BLOCK.wav"),
"PLAY": pygame.mixer.Sound("sound/PLAY.wav"),
"STOP": pygame.mixer.Sound("sound/STOP.wav"),
"SAVE": pygame.mixer.Sound("sound/SAVE.wav"),
"TOOL": pygame.mixer.Sound("sound/TOOL.wav"),
"RMFRAME": pygame.mixer.Sound("sound/REMOVEPAGE.wav"),
"CFRAME": pygame.mixer.Sound("sound/COPYPAGE.wav"),
"PFRAME": pygame.mixer.Sound("sound/PASTEPAGE.wav"),
"BACK": pygame.mixer.Sound("sound/BACK.wav")
}
# Load images
images = {
"PEN": pygame.image.load("assets/pen.png"),
"ERASER": pygame.image.load("assets/eraser.png"),
"ERASEBUTTON": pygame.image.load("assets/erasebutton.png"),
"FRAME_L": pygame.image.load("assets/frame_l.png"),
"FRAME_R": pygame.image.load("assets/frame_r.png"),
"STOP": pygame.image.load("assets/stop.png"),
"PLAY": pygame.image.load("assets/play.png"),
"BLANK": pygame.image.load("assets/blank.png"),
"RED": pygame.image.load("assets/red.png"),
"BLUE": pygame.image.load("assets/blue.png"),
"THIRDCOLORBTN": pygame.image.load("assets/third_color_button.png"),
}
# Play startup sound
sounds["OPEN"].play()
# Create frame list and initial canvas
frames = [pygame.Surface((CANVAS_WIDTH, CANVAS_HEIGHT), pygame.SRCALPHA)]
frames[0].fill(WHITE)
current_frame = 0
is_playing = False
playback_speed = DEFAULT_SPEED # Default playback speed
# Initial state
drawing = False
color = BLACK
undo_stack = [frames[current_frame].copy()]
# Color palette for each frame
frame_colors = {
BLACK: BLACK,
WHITE: WHITE,
RED: RED
}
# Function to draw the toolbar
def draw_toolbar():
# Skip drawing static parts of the toolbar while user is painting
if drawing == False or color == WHITE:
pygame.draw.rect(screen, ORANGE, (0, CANVAS_HEIGHT, WINDOW_WIDTH, TOOLBAR_HEIGHT))
# Draw color buttons with images
screen.blit(images["PEN"], (10, CANVAS_HEIGHT + 10))
screen.blit(images["ERASER"], (40, CANVAS_HEIGHT + 10))
pygame.draw.rect(screen, BLACK, (70, CANVAS_HEIGHT + 10, 20, 20), 2) # Red/Blue color selector outline
pygame.draw.rect(screen, WHITE, (70, CANVAS_HEIGHT + 10, 20, 20)) # Red/Blue color selector background
# Draw Erase button with image
erase_button_img = images["ERASEBUTTON"]
erase_button_rect = erase_button_img.get_rect(topleft=(100, CANVAS_HEIGHT + 10))
screen.blit(erase_button_img, erase_button_rect)
# Draw frame navigation buttons with images
frame_left_img = images["FRAME_L"]
frame_left_rect = frame_left_img.get_rect(topleft=(170, CANVAS_HEIGHT + 10))
screen.blit(frame_left_img, frame_left_rect)
frame_right_img = images["FRAME_R"]
frame_right_rect = frame_right_img.get_rect(topleft=(210, CANVAS_HEIGHT + 10))
screen.blit(frame_right_img, frame_right_rect)
# Draw Play/Stop button with image overlay
play_stop_img = images["STOP"] if is_playing else images["PLAY"]
play_stop_img_rect = play_stop_img.get_rect(center=(130, CANVAS_HEIGHT + 50))
screen.blit(play_stop_img, play_stop_img_rect)
# Draw Export button with blank image
export_button_img = images["BLANK"]
export_button_rect = export_button_img.get_rect(topleft=(170, CANVAS_HEIGHT + 40))
screen.blit(export_button_img, export_button_rect)
# Draw Export text with smaller font size
export_text = font.render('Export', True, ORANGE)
export_text = pygame.transform.scale(export_text, (int(export_text.get_width() * 0.8), int(export_text.get_height() * 0.8)))
screen.blit(export_text, (177, CANVAS_HEIGHT + 43))
# Draw third color button with dynamic image
if color == RED:
color_button_img = images["RED"]
elif color == BLUE:
color_button_img = images["BLUE"]
else:
color_button_img = images["THIRDCOLORBTN"]
screen.blit(color_button_img, (70, CANVAS_HEIGHT + 10))
# Draw frame number text
frame_text = font.render(f'{current_frame + 1} / {len(frames)}', True, FRAME_COUNTER_COLOR)
screen.blit(frame_text, (WINDOW_WIDTH - frame_text.get_width() - 10, 5))
# Function to get the current speed option
def get_current_speed_option():
for option, speed in SPEED_OPTIONS.items():
if speed == playback_speed:
return option
return "N/A"
# Function to save the current state to the undo stack
def save_state():
if len(undo_stack) >= UNDO_STACK_SIZE:
undo_stack.pop(0)
undo_stack.append(frames[current_frame].copy())
# Function to handle erase
def erase():
sounds["ERASE"].play()
frames[current_frame].fill(WHITE)
# Function to draw the cursor overlay
def draw_cursor_overlay(x, y):
if color == WHITE and y < CANVAS_HEIGHT:
screen_refresh()
pygame.draw.rect(screen, CURSOR_COLOR, (x - WHITE_BRUSH_SIZE // 2, y - WHITE_BRUSH_SIZE // 2, WHITE_BRUSH_SIZE, WHITE_BRUSH_SIZE), 1)
# Function to switch between red and blue
def switch_color():
global color, last_red_blue_color
sounds["COLOUR"].play()
if color == RED:
color = BLUE
last_red_blue_color = BLUE
replace_color(RED, BLUE)
else:
color = RED
last_red_blue_color = RED
replace_color(BLUE, RED)
# Function to replace all occurrences of a color with another color in the current frame
def replace_color(old_color, new_color):
for y in range(CANVAS_HEIGHT):
for x in range(CANVAS_WIDTH):
if frames[current_frame].get_at((x, y))[:3] == old_color:
frames[current_frame].set_at((x, y), new_color + (frames[current_frame].get_at((x, y))[3],))
# Function to navigate frames
def navigate_frames(direction):
global current_frame, frames
if direction == 'left':
if current_frame == 0:
sounds["BLOCK"].play()
else:
current_frame = max(current_frame - 1, 0)
sounds["FRAME_LEFT"].play()
elif direction == 'right':
if current_frame < len(frames) - 1:
current_frame += 1
sounds["FRAME_RIGHT"].play()
else:
if len(frames) < MAX_FRAMES:
frames.append(pygame.Surface((CANVAS_WIDTH, CANVAS_HEIGHT), pygame.SRCALPHA))
current_frame += 1
frames[current_frame].fill(WHITE)
sounds["NEW_FRAME"].play()
else:
sounds["BLOCK"].play()
# Function to play frames
def play_frames():
global is_playing, current_frame
is_playing = True
sounds["PLAY"].play()
clock = pygame.time.Clock()
while is_playing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
x, y = event.pos
if 100 <= x <= 160 and CANVAS_HEIGHT + 40 <= y <= CANVAS_HEIGHT + 60:
is_playing = False
sounds["STOP"].play()
return
elif event.type == pygame.KEYDOWN:
if pygame.K_1 <= event.key <= pygame.K_8:
option = int(pygame.key.name(event.key))
set_speed_option(option)
sounds["TOOL"].play()
if current_frame >= len(frames) - 1:
current_frame = 0
else:
current_frame += 1
screen.fill(WHITE)
screen.blit(frames[current_frame], (0, 0))
draw_toolbar()
pygame.display.flip()
clock.tick(playback_speed)
# Function to set the playback speed option
def set_speed_option(option):
global playback_speed
if option in SPEED_OPTIONS:
playback_speed = SPEED_OPTIONS[option]
# Function to check for color conflicts
def check_color_conflict(x, y):
if color == RED or color == BLUE:
red_present = blue_present = False
for px in range(max(0, x - BRUSH_SIZE // 2), min(CANVAS_WIDTH, x + BRUSH_SIZE // 2)):
for py in range(max(0, y - BRUSH_SIZE // 2), min(CANVAS_HEIGHT, y + BRUSH_SIZE // 2)):
px_color = frames[current_frame].get_at((px, py))[:3]
if px_color == RED:
red_present = True
elif px_color == BLUE:
blue_present = True
if red_present and blue_present:
raise Exception("Cannot draw red on a frame with blue.")
print("No color conflict detected.")
# Function to handle drawing on the canvas
def handle_drawing(x, y):
global color
if y < CANVAS_HEIGHT:
red_present = is_color_present(RED)
blue_present = is_color_present(BLUE)
if color == RED and blue_present:
color = BLUE
elif color == BLUE and red_present:
color = RED
pygame.draw.rect(frames[current_frame], color, (x - BRUSH_SIZE // 2, y - BRUSH_SIZE // 2, BRUSH_SIZE, BRUSH_SIZE))
# Function to show the export progress window using Pygame
def show_export_progress(progress):
progress_screen = pygame.display.set_mode((300, 100))
progress_screen.fill(WHITE)
pygame.display.set_caption("Export Progress")
progress_label = font.render(f"Exporting frame {progress + 1} of {len(frames)}", True, BLACK)
progress_screen.blit(progress_label, (50, 40))
pygame.display.flip()
return progress_screen
# Function to generate a random filename
def generate_filename():
random_numbers1 = ''.join(random.choices(string.digits, k=3))
random_letters = ''.join(random.choices(string.ascii_uppercase, k=6))
random_numbers2 = ''.join(random.choices(string.digits, k=3))
random_numbers3 = ''.join(random.choices(string.digits, k=4))
return f"{random_numbers1}{random_letters}_{random_numbers2}0{random_letters[1]}{random_numbers2}X{random_numbers2}0{random_numbers1}0{random_numbers3}XXXX0_000.mp4"
# Function to export frames
def export_frames():
sounds["SAVE"].play()
if not os.path.exists("frames"):
os.makedirs("frames")
for idx, frame in enumerate(frames):
progress_screen = show_export_progress(idx)
pygame.image.save(frame, f"frames/frame_{idx:04d}.png")
# Use ffmpeg to create a video from the frames
subprocess.run([
"ffmpeg", "-y", "-framerate", str(playback_speed), "-i", "frames/frame_%04d.png",
"-pix_fmt", "yuv420p", generate_filename()
])
# Delete the frames folder
shutil.rmtree("frames")
# Close the progress window
pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption('Pynote Studio')
# Function to enforce color replacement rule if both red and blue are found on the same frame
def enforce_color_rule():
red_found = False
blue_found = False
for y in range(CANVAS_HEIGHT):
for x in range(CANVAS_WIDTH):
px_color = frames[current_frame].get_at((x, y))[:3]
if px_color == RED:
red_found = True
elif px_color == BLUE:
blue_found = True
if red_found and blue_found:
break
if red_found and blue_found:
break
if red_found and blue_found:
replace_color(BLUE, RED)
# Function to play the drawing sound
def play_draw_sound():
if not pygame.mixer.get_busy(): # Check if any sound is currently playing
DRAW_SOUND.play(loops=-1) # Start playing the drawing sound continuously
# Function to stop the drawing sound
def stop_draw_sound():
DRAW_SOUND.stop() # Stop playing the drawing sound
# Function to check if a specific color is present in the current frame
def is_color_present(color):
for y in range(CANVAS_HEIGHT):
for x in range(CANVAS_WIDTH):
if frames[current_frame].get_at((x, y))[:3] == color:
return True
return False
def screen_refresh():
screen.fill(WHITE)
screen.blit(frames[current_frame], (0, 0))
draw_toolbar()
def screen_refresh_draw():
screen.blit(frames[current_frame], (0, 0))
draw_toolbar()
# Function to remove the current frame
def remove_frame():
global current_frame, frames
if len(frames) > 1:
sounds["RMFRAME"].play()
frames.pop(current_frame)
if current_frame >= len(frames):
current_frame = max(0, current_frame - 1)
else:
sounds["BLOCK"].play()
# Function to copy the current frame
def copy_frame():
global copied_frame
copied_frame = frames[current_frame].copy()
sounds["CFRAME"].play()
# Function to paste the copied frame
def paste_frame():
global copied_frame
if copied_frame:
frames[current_frame] = copied_frame.copy()
sounds["PFRAME"].play()
screen_refresh()
# Function to save the project
def save_project():
sounds["SAVE"].play()
# Create the temp_frames directory if it doesn't exist
if not os.path.exists('.temp_frames'):
os.makedirs('.temp_frames')
# Generate a random filename
filename = 'rawflipnote.rawppm'
# Create a zip archive
with zipfile.ZipFile(filename, 'w') as project_zip:
for idx, frame in enumerate(frames):
frame_filename = f'FRAME{idx+1:03d}.JPG'
frame_path = os.path.join('.temp_frames', frame_filename)
pygame.image.save(frame, frame_path)
project_zip.write(frame_path, arcname=frame_filename)
os.remove(frame_path) # Clean up temporary frame file
# Delete the temp_frames folder
shutil.rmtree('.temp_frames')
# Function to open a project
def open_project():
sounds["SAVE"].play()
# Create the temp_frames directory if it doesn't exist
if not os.path.exists('.temp_frames'):
os.makedirs('.temp_frames')
global frames, current_frame
with zipfile.ZipFile('rawflipnote.rawppm', 'r') as project_zip:
frames = []
for file in sorted(project_zip.namelist()):
if file.endswith('.JPG'):
frame = pygame.image.load(project_zip.open(file))
frames.append(frame)
current_frame = 0
screen_refresh()
# Delete the temp_frames folder
shutil.rmtree('.temp_frames')
font_path = 'assets/font.otf'
font_size = 12
def display_text_window():
global screen
# Play the tool sound
info_sound.play()
# Save the current screen state
saved_screen = screen.copy()
# Create a new window
info_width, info_height = 400, 350
info_window = pygame.display.set_mode((info_width, info_height))
pygame.display.set_caption('About Pynote Studio')
# Set up custom font and text
pygame.freetype.init()
try:
font = pygame.freetype.Font(font_path, font_size)
except FileNotFoundError:
font = pygame.freetype.SysFont(None, font_size) # Fallback to default font if custom font not found
text = "<br>Keyboard Shortcuts:<br>I - Show Info Menu<br>B - Switch between Red and Blue<br>X - Erase current Page<br>< Arrow Key - Navigate Page Left<br>> Arrow Key - Navigate Page Right<br>Backspace - Delete current Page<br>CTRL + C - Copy current Page<br>CTRL + V - Paste current Page<br>CTRL + S - Save Project (as rawflipnote.rawppm)<br>CTRL + O - Open Project (from rawflipnote.rawppm)<br>CTRL + E - Export as MP4" # I know it looks out of place but do not remove that first <br>! -lexi
# Load splash image
splash_image = pygame.image.load('assets/splash.png')
splash_rect = splash_image.get_rect()
splash_rect.top = 10
splash_rect.centerx = info_width // 2
# Display the text in the new window
orange_color = (251, 97, 0)
white_color = (255, 255, 255)
info_window.fill(orange_color) # Orange background
# Render each line of text
lines = text.split('<br>') # you can tell i'm used to HTML, lol -lexi
line_height = font.get_sized_height()
y = splash_rect.bottom + 10 # Start below splash image
line_gap = 8 # Adjust the gap between lines here
for line in lines:
font.render_to(info_window, (5, y), line, white_color) # White text, 5px from left
y += line_height - line_gap # Subtract the gap from the line height
y += line_gap # Add the gap after each line
# Load the back button image
back_button_image = pygame.image.load('assets/BACK.png')
back_button_rect = back_button_image.get_rect()
back_button_rect.topleft = (info_width - back_button_rect.width - 10, info_height - back_button_rect.height - 10)
# Draw the splash image and back button
info_window.blit(splash_image, splash_rect)
info_window.blit(back_button_image, back_button_rect.topleft)
# Render additional centered text at the top
additional_text = "© RekuBuild 2024"
additional_text_rect = font.get_rect(additional_text)
additional_text_rect.centerx = info_width // 2
additional_text_rect.top = splash_rect.bottom + 5
font.render_to(info_window, additional_text_rect.topleft, additional_text, white_color)
# Render additional centered text above back button - ignore that this is called a hyperlink, i wanted it to link to the github but m lazy -w- -lexi
hyperlink_text = "Pynote Studio v0.2 - by RekuNote"
hyperlink_text_rect = font.get_rect(hyperlink_text)
hyperlink_text_rect.centerx = info_width // 2
hyperlink_text_rect.bottom = back_button_rect.top - 10 # Position above the back button
font.render_to(info_window, hyperlink_text_rect.topleft, hyperlink_text, white_color)
pygame.display.flip()
# Keep the window open until it's closed
info_running = True
while info_running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
info_running = False
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
sounds["BACK"].play()
info_running = False
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse_pos = event.pos
if back_button_rect.collidepoint(mouse_pos):
sounds["BACK"].play()
info_running = False
# Return to the main application loop
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption('Pynote Studio')
# Restore the saved screen state
screen.blit(saved_screen, (0, 0))
pygame.display.flip()
# Event handling loop
running = True
previous_pos = None # Track previous mouse position
# Control framerate
fps_clock = pygame.time.Clock()
# Initial screen render
screen_refresh()
while running:
mouse_x, mouse_y = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
x, y = event.pos
if y < CANVAS_HEIGHT:
drawing = True
save_state()
handle_drawing(x, y)
enforce_color_rule()
screen_refresh_draw()
play_draw_sound() # Start playing the drawing sound continuously
elif CANVAS_HEIGHT <= y < CANVAS_HEIGHT + TOOLBAR_HEIGHT:
# Handle toolbar button clicks
if 10 <= x <= 30 and CANVAS_HEIGHT + 10 <= y <= CANVAS_HEIGHT + 30:
color = BLACK
sounds["COLOUR"].play()
screen_refresh()
elif 40 <= x <= 60 and CANVAS_HEIGHT + 10 <= y <= CANVAS_HEIGHT + 30:
color = WHITE
sounds["COLOUR"].play()
screen_refresh()
elif 70 <= x <= 90 and CANVAS_HEIGHT + 10 <= y <= CANVAS_HEIGHT + 30:
switch_color()
enforce_color_rule()
screen_refresh()
elif 100 <= x <= 160 and CANVAS_HEIGHT + 10 <= y <= CANVAS_HEIGHT + 30:
erase()
enforce_color_rule()
screen_refresh()
elif 170 <= x <= 200 and CANVAS_HEIGHT + 10 <= y <= CANVAS_HEIGHT + 30:
navigate_frames('left')
screen_refresh()
elif 210 <= x <= 240 and CANVAS_HEIGHT + 10 <= y <= CANVAS_HEIGHT + 30:
navigate_frames('right')
screen_refresh()
elif 100 <= x <= 160 and CANVAS_HEIGHT + 40 <= y <= CANVAS_HEIGHT + 60:
if is_playing:
is_playing = False
sounds["STOP"].play()
else:
play_frames()
screen_refresh()
elif 170 <= x <= 230 and CANVAS_HEIGHT + 40 <= y <= CANVAS_HEIGHT + 60:
export_frames()
screen_refresh()
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
drawing = False
previous_pos = None # Reset previous position
stop_draw_sound() # Stop playing the drawing sound when mouse is released
screen_refresh()
elif event.type == pygame.MOUSEMOTION:
if drawing:
x, y = event.pos
if y < CANVAS_HEIGHT:
# Draw a line from previous position to current position
if previous_pos:
current_brush_size = WHITE_BRUSH_SIZE if color == WHITE else BRUSH_SIZE
pygame.draw.line(frames[current_frame], color, previous_pos, (x, y), current_brush_size)
# Removed by IC - fixed program locking up while drawing - How is this needed? You cannot change the color while drawing.
#enforce_color_rule() # Enforce the color rule on mouse motion
screen_refresh_draw()
# Calculate mouse movement speed
if previous_pos:
distance = math.sqrt((x - previous_pos[0]) ** 2 + (y - previous_pos[1]) ** 2)
max_distance = 5
volume = min(distance / max_distance * MAX_VOLUME, MAX_VOLUME) # Adjust volume based on distance
DRAW_SOUND.set_volume(volume) # Set the volume of the drawing sound
previous_pos = (x, y) # Update previous position
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_BACKSPACE:
remove_frame()
screen_refresh()
elif event.key == pygame.K_b:
switch_color()
enforce_color_rule()
screen_refresh()
elif event.key == pygame.K_x:
erase()
enforce_color_rule()
screen_refresh()
elif event.key == pygame.K_LEFT:
navigate_frames('left')
screen_refresh()
elif event.key == pygame.K_RIGHT:
navigate_frames('right')
screen_refresh()
elif event.key == pygame.K_e:
if pygame.key.get_mods() & pygame.KMOD_CTRL:
export_frames()
screen_refresh()
elif event.key == pygame.K_c:
if pygame.key.get_mods() & pygame.KMOD_CTRL:
copy_frame()
elif event.key == pygame.K_v:
if pygame.key.get_mods() & pygame.KMOD_CTRL:
paste_frame()
elif event.key == pygame.K_s:
if pygame.key.get_mods() & pygame.KMOD_CTRL:
save_project()
elif event.key == pygame.K_o:
if pygame.key.get_mods() & pygame.KMOD_CTRL:
open_project()
elif event.key == pygame.K_i:
display_text_window()
draw_cursor_overlay(mouse_x, mouse_y)
pygame.display.flip()
fps_clock.tick(60)
# Done! Time to quit.
pygame.quit()
sys.exit()