From 3a396753ef985699b52dd056796f338415c99b37 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 31 Oct 2021 00:31:46 +0100 Subject: added gif image generation --- gif.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 gif.py (limited to 'gif.py') diff --git a/gif.py b/gif.py new file mode 100644 index 0000000..9f0c699 --- /dev/null +++ b/gif.py @@ -0,0 +1,64 @@ +import glob +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("#282a2e"), + color("#373b41"), + color("#f58f44") + ] + +sorted(colors, key=rgb_to_v) +p = len(colors) + +def make(filename, inp=None): + w = int(256 / p) * p + h = int(256 / 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) + + 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 == replace: + image.putpixel((x,y), c) + else: + image.putpixel((x,y), c) + + frames.append(image) + + + frames[0].save(filename, format="GIF", append_images=frames[1:], save_all=True, duration=100, loop=0) + +make("images/bg.gif") +make("images/remotecontrol.gif", inp="images/remotecontrol.png") + + -- cgit v1.2.1