From 6d1ce99a6a3a6540620f6b374e94fa5d22c7354a Mon Sep 17 00:00:00 2001 From: bfayers Date: Thu, 12 Jan 2023 19:08:38 +0000 Subject: [PATCH 1/2] Add blending feature by changing transparency over a period --- epic.py | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/epic.py b/epic.py index f4a3341..653d474 100644 --- a/epic.py +++ b/epic.py @@ -15,6 +15,8 @@ # Settings check_delay = 120 #minutes rotate_delay = 20 #seconds +enable_blending = True #True/False +blending_duration = 5 #second - how long to spend blending between 2 images # Set up the drawing window screen = pygame.display.set_mode([480,480], pygame.FULLSCREEN) @@ -64,7 +66,31 @@ def save_photos(imageurls): counter+=1 print("photos saved") -def rotate_photos(num_photos, rotate_delay): +def blend_between_photos(old_image, new_image, target_duration): + print("Attempting to blend between old and new images") + + transparency = 0 + #Place the old image down first + screen.blit(old_image, (0,0)) + #Set the new image to be completely transparent + new_image.set_alpha(transparency) + screen.blit(new_image, (0,0)) + pygame.display.flip() + + while transparency < 255: + #Update transparency for new image + transparency += 1 + new_image.set_alpha(transparency) + + #Place both images down, old one first, new one with adjusted transparency second. + screen.blit(old_image, (0,0)) + screen.blit(new_image, (0,0)) + pygame.display.flip() + #Delay the loop to blend over the target duration (in seconds) + time.sleep(target_duration/255) + + +def rotate_photos(num_photos, rotate_delay, blend_enabled=False, blend_time=5): counter=0 while counter 1 and blend_enabled: + old_image = pygame.image.load(r"./"+str(counter-1)+".jpg") + blend_between_photos(old_image, new_image, 5) + else: + # Display image + screen.blit(new_image, (0,0)) + pygame.display.flip() + counter+=1 # How many seconds to wait between changing images @@ -123,7 +152,7 @@ def rotate_photos(num_photos, rotate_delay): print("No new images") # Show each photo in order. - rotate_photos(num_photos, rotate_delay) + rotate_photos(num_photos, rotate_delay, enable_blending, blending_duration) # Done! Time to quit. pygame.quit() From ede8034df6ee32f3eb8df71242a2bd18d17ed34a Mon Sep 17 00:00:00 2001 From: bfayers Date: Fri, 13 Jan 2023 12:14:50 +0000 Subject: [PATCH 2/2] actually use blend time variable --- epic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epic.py b/epic.py index 653d474..201dbc0 100644 --- a/epic.py +++ b/epic.py @@ -102,7 +102,7 @@ def rotate_photos(num_photos, rotate_delay, blend_enabled=False, blend_time=5): new_image = pygame.image.load(r"./"+str(counter)+".jpg") if counter > 1 and blend_enabled: old_image = pygame.image.load(r"./"+str(counter-1)+".jpg") - blend_between_photos(old_image, new_image, 5) + blend_between_photos(old_image, new_image, blend_time) else: # Display image screen.blit(new_image, (0,0))