883 B
883 B
Rendering an animated GIF in pygame
from PIL import Image
import pygame
import pygame.image
def create_images():
images = []
for i in range(6):
surface = pygame.Surface((256, 256))
surface.fill((255 - i * 50, 255, i * 50))
image = Image.frombytes(
"RGBA", (256, 256), pygame.image.tostring(surface, "RGBA", False)
)
images.append(image)
return images
images = create_images()
images[0].save(
"animated.gif",
format="GIF",
append_images=images[1:],
save_all=True,
duration=300,
loop=0,
)
return "animated.gif"