summaryrefslogtreecommitdiff
path: root/images/gif.py
blob: 26e8408343c132e839d6486397dee7aa75026ebc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
import glob
import sys
import os
import math
import random
from PIL import Image


def color(hex_value):
    h = hex_value.lstrip('#')
    while len(h) < 8:
        h += "f" 
    return tuple(int(h[i:i+2], 16) for i in (0, 2, 4, 6))

def rgb_to_v(c):
    r, g, b = c[0]/255.0, c[1]/255.0, c[2]/255.0
    mx = max(r, g, b)
    v = mx*100
    return v

replace = color("#f58f44")
colors = [
        color("#191919"),
        color("#373b41"),
        ]

def make(colors, inp=None):
    p = len(colors)
    w = int(128 / p) * p
    h = int(128 / p) * p

    frames = []

    for i in range(int(p*1*math.pi)):
        if inp is None:
            image = Image.new("RGBA", (w, h), colors[0])
        else:
            image = Image.open(inp).convert("RGBA")

        for x in range(image.width):
            for y in range(image.height):
                f = 2
                r = random.randint(-f, f)
                z = (i) - (y/(p/4)) + r
                v = math.floor( (math.sin(z) + 1) * len(colors) * 0.5)
                c = colors[v]
                if inp is not None:
                    existing = image.getpixel((x, y)) 
                    if existing[:3] == replace[:3]:
                        image.putpixel((x,y), c)
                else:
                    image.putpixel((x,y), c)

        frames.append(image.convert("P"))


    frames[0].save(sys.stdout, mode="P", format="GIF", append_images=frames[1:], save_all=True, duration=100, loop=0)


template = None
if len(sys.argv) > 1 and os.path.exists(sys.argv[1]):
    template = sys.argv[1]
    colors = colors + [ color("#f58f44") ]

sorted(colors, key=rgb_to_v)
make(colors, inp=template)
#make("dist/images/remotecontrol.gif", colors2, inp="images/remotecontrol-small.png")