Skip to content

Instantly share code, notes, and snippets.

@vincentdchan
Created September 26, 2017 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincentdchan/e120f3cacf88efbba3e51fa1b0084086 to your computer and use it in GitHub Desktop.
Save vincentdchan/e120f3cacf88efbba3e51fa1b0084086 to your computer and use it in GitHub Desktop.
SpinAnimation
"""
Author: DZ Chan
Date: 2017-09-24
Description: This is a animation generator
"""
from PIL import Image, ImageDraw
import sys, math
'''
according to the definition in WIKI:
https://zh.wikipedia.org/wiki/%E6%9E%81%E5%9D%90%E6%A0%87%E7%B3%BB
'''
def clearPixels(img, theta1, theta2):
SIZE = img.size
CENTER_POINT = (SIZE[0]/2, SIZE[1]/2)
for x in range(SIZE[0]):
for y in range(SIZE[1]):
relative_point = (x - CENTER_POINT[0], y - CENTER_POINT[1])
theta = math.atan2(relative_point[1], relative_point[0])
theta = theta * 180 / math.pi + 180
if theta2 > 360:
if theta >= theta1 or theta < theta2 - 360:
draw = ImageDraw.Draw(img, 'RGBA')
draw.point([x, y], (0, 0, 0, 0)) # write null pixel
continue
if theta >= theta1 and theta < theta2:
draw = ImageDraw.Draw(img, 'RGBA')
draw.point([x, y], (0, 0, 0, 0)) # write null pixel
if __name__ == '__main__':
img = Image.open(sys.argv[1]).convert('RGBA')
MAX_NUM = int(sys.argv[2])
for i in range(MAX_NUM):
copy = img.copy()
angles = int((i / MAX_NUM) * 360)
print('generating angle:' + str(angles))
clearPixels(copy, 90, angles+90)
copy.save('red-animations/red_ani_' + str(i) + '.png', 'PNG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment