I have a proof of concept in Python where it just keeps redrawing a window, keeps track of the time, and removes images as the time passes. This seems fine, but feels clunky, not sure I trust this to run if there were 1000 images. Example shared below.
Regardless, is there a better way to do this with another language? If so, anyone got an example?
import pygame
import win32api
import win32con
import win32gui
import time
import random
class testHug():
def __init__(self):
pygame.init()
self.screen_width = 800
self.screen_height = 600
self.screen = pygame.display.set_mode((self.screen_width, self.screen_height))
self.hwnd = pygame.display.get_wm_info()["window"]
win32gui.SetWindowLong(self.hwnd, win32con.GWL_EXSTYLE, win32gui.GetWindowLong(
self.hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED)
win32gui.SetLayeredWindowAttributes(self.hwnd, win32api.RGB(255, 0, 128), 0, win32con.LWA_COLORKEY)
self.screen.fill((255, 0, 128))
pygame.display.flip()
self.image_list = [
pygame.image.load("image.png"),
pygame.image.load("image2.png"),
pygame.image.load("image3.png")
]
self.duration = 4000
self.killtime = 10000
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict = {'user1' : {'image': pygame.image.load("image.png"), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)} }
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict['user2'] = {'image': pygame.image.load("image2.png"), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)}
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict['user3'] = {'image': pygame.image.load("image3.png"), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)}
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict['user4'] = {'image': pygame.image.load("image4.png"), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)}
self.running = True
def processImages(self, user, image):
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict[user] = {'image': pygame.image.load(image), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)}
self.image_index = 0
while self.running:
elapsed_time = pygame.time.get_ticks() - self.current_ticker_time
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
if elapsed_time >= self.killtime and self.image_index >= len(self.image_dict):
break
if elapsed_time >= self.duration and self.image_index < len(self.image_dict):
self.image_index += 1
self.screen.fill((255, 0, 128))
pygame.display.flip()
for x in range(0, self.image_index):
if (self.image_index <= len(self.image_dict)):
imageToGrab = "user"+ str(x+1)
if self.image_dict[imageToGrab]["shown"] == 0:
self.image_dict[imageToGrab]["starttime"] = pygame.time.get_ticks()
self.image_dict[imageToGrab]["shown"] = 1
imageElapsedTime = pygame.time.get_ticks() - int(self.image_dict[imageToGrab]["starttime"])
print("starttime, imageElapsedTime, and imageToGrab", self.image_dict[imageToGrab]["starttime"], imageElapsedTime, imageToGrab)
if imageElapsedTime < (self.duration * 2.5):
image_rect = self.image_dict[imageToGrab]["image"].get_rect()
image_rect.center = ((self.screen_width / 2)+self.image_dict[imageToGrab]["widthmodifier"], (self.screen_height / 2)+self.image_dict[imageToGrab]["heightmodifier"])
self.screen.blit(self.image_dict[imageToGrab]["image"], image_rect)
pygame.display.flip() #redraw screen
self.current_ticker_time = pygame.time.get_ticks()
pygame.quit()
if __name__ == '__main__':
th = testHug()
th.processImages('user5', "image5.png")