# Demo: Fast double-buffer blitting of images in memory with pygame in Raspian-Stretch
from os import listdir
import time
import pygame
# Initialize pygame
pygame.init()
# create fullscreen display
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN | pygame.DOUBLEBUF | pygame.NOFRAME | pygame.HWSURFACE)
# load all image files (BMP) in folder 'images' into surfaces in RAM
images = []
files = listdir('fotos')
for f in files:
img = pygame.image.load('fotos/'+f).convert()
images.append(img)
# blit 100 images
cnt = len(images)
t_start = time.time()
for i in range(100):
# blit next image into screen buffer
screen.blit(images[i % cnt], (0,0))
# load screen buffer into actual screen
pygame.display.flip()
# show fps
sec = time.time()-t_start
print("fps: "+str(100/sec)) # 54
# clean up
pygame.quit()