Created
December 1, 2016 17:06
-
-
Save TimSC/156b652564d1de97d8a8e3bb181ad33c to your computer and use it in GitHub Desktop.
Add rotating triangles around an icon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw | |
import math, os | |
def DrawTri(im, draw, ang): | |
vec = [math.cos(ang), -math.sin(ang)] | |
cross = [vec[1], -vec[0]] | |
cent = [im.size[0]/2.0, im.size[1]/2.0] | |
ln = min(cent) | |
pos = (cent[0]+vec[0]*ln, cent[1]+vec[1]*ln) | |
tri = (cent[0]+vec[0]*ln*0.8, cent[1]+vec[1]*ln*0.8, pos[0]+ln*0.2*cross[0], pos[1]+ln*0.2*cross[1], pos[0]-ln*0.2*cross[0], pos[1]-ln*0.2*cross[1]) | |
draw = ImageDraw.Draw(im) | |
draw.polygon(tri, fill=(255,255,255,192)) | |
del draw | |
if __name__=="__main__": | |
for fina in ["arrows.png", "broken-amphora.png", "luxury.png", "pot-of-gold.png", "pyramid-of-the-sun.png", "question.png"]: | |
finaSp = os.path.splitext(fina) | |
print finaSp | |
for i in range(10): | |
im = Image.open(fina) | |
im = im.convert("RGBA") | |
ang = i * math.pi / 20.0 | |
draw = ImageDraw.Draw(im) | |
DrawTri(im, draw, ang) | |
DrawTri(im, draw, ang + math.pi/2.0) | |
DrawTri(im, draw, ang + math.pi) | |
DrawTri(im, draw, ang + math.pi*1.5) | |
del draw | |
im.save("{}{}{}".format(finaSp[0], i, finaSp[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment