craiyon logo

A stylized geometric hammerhead shark and a whale swim gracefully in clear blue water with light rays.

A stylized geometric hammerhead shark and a whale swim gracefully in clear blue water with light rays.

from PIL import Image, ImageDraw import math # animation settings SIZE = 400 BG = (11, 60, 63) COLOR = (62, 242, 194) FRAMES = 40 creatures = [] # draw functions def draw_shark(draw): draw.polygon([(90,210),(200,180),(310,210),(280,240),(200,230),(120,240)], fill=COLOR) def draw_hammerhead(draw): draw.polygon([(90,210),(200,180),(310,210),(290,190),(330,190),(330,230),(290,230)], fill=COLOR) def draw_dolphin(draw): draw.polygon([(110,220),(200,190),(290,220),(280,230),(200,210),(120,230)], fill=COLOR) def draw_whale(draw): draw.polygon([(80,230),(200,200),(320,230),(300,240),(200,230),(120,240)], fill=COLOR) draw_funcs = [draw_shark, draw_hammerhead, draw_dolphin, draw_whale] # render creature images for fn in draw_funcs: img = Image.new("RGBA", (SIZE, SIZE), BG) draw = ImageDraw.Draw(img) fn(draw) creatures.append(img) frames = [] for i in range(len(creatures)): curr = creatures[i] nxt = creatures[(i + 1) % len(creatures)] # hold still for _ in range(5): frames.append(curr.copy()) # cross-fade for t in range(10): blend = Image.blend(curr, nxt, t/10) frames.append(blend) frames[0].save( "sea_loop.gif", save_all=True, append_images=frames[1:], duration=100, loop=0 ) See more