1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #!/usr/bin/env python3
- from PIL import Image
- from math import sin, cos, pi
- def main():
- bg = Image.open('./stars.png')
- cookie = Image.open('./cookie.png').resize((100, 100))
- cookie_mask = cookie.split()[0].point(lambda i: i != 0 and 255)
- muffin = Image.open('./muffin.png').resize((100, 100))
- muffin_mask = muffin.split()[0].point(lambda i: i != 0 and 255)
- doughnut = Image.open('./doughnut.png').resize((100, 100))
- doughnut_mask = doughnut.split()[0].point(lambda i: i != 0 and 255)
- snacks = [cookie, muffin, doughnut]
- masks = [cookie_mask, muffin_mask, doughnut_mask]
- n = 150
- def combine(t):
- A = 0.1
- w = 6*2*pi/n
- bg_copy = bg.copy()
- # left_c.paste(left, box=(offset, 0))
- # right_c.paste(right, box=(-offset, 0))
- N = 10
- radius = 400
- center = 450, 450
- for i in range(N+1):
- strain_x = 1 + A*sin(w*t)
- strain_y = 1 - A*sin(w*t)
- theta = i*2*pi/(N+1)
- x = int(center[0] + strain_x*radius*cos(theta))
- y = int(center[1] + strain_y*radius*sin(theta))
- bg_copy.paste(snacks[i % 3], mask=masks[i % 3], box=(x, y))
- # bg.show()
- return bg_copy
- # combine(0)
- frames = [combine(i) for i in range(n)]
- frames[0].save('snacks.gif', save_all=True, append_images=frames[1:], duration=int(1000/30), loop=0)
- if __name__ == '__main__':
- main()
|