2021-10-30 23:31:46 +00:00
|
|
|
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("#373b41"),
|
|
|
|
]
|
2022-11-29 13:39:17 +00:00
|
|
|
colors2 = colors + [
|
|
|
|
color("#f58f44")
|
|
|
|
]
|
2021-10-30 23:31:46 +00:00
|
|
|
|
|
|
|
sorted(colors, key=rgb_to_v)
|
2022-11-29 13:39:17 +00:00
|
|
|
sorted(colors2, key=rgb_to_v)
|
2021-10-30 23:31:46 +00:00
|
|
|
|
2022-11-29 13:39:17 +00:00
|
|
|
def make(filename, colors, inp=None):
|
|
|
|
p = len(colors)
|
2021-11-01 22:53:48 +00:00
|
|
|
w = int(128 / p) * p
|
|
|
|
h = int(128 / p) * p
|
2021-10-30 23:31:46 +00:00
|
|
|
|
|
|
|
frames = []
|
|
|
|
|
|
|
|
for i in range(int(p*1*math.pi)):
|
|
|
|
if inp is None:
|
|
|
|
image = Image.new("RGBA", (w, h), colors[0])
|
|
|
|
else:
|
2021-11-01 22:53:48 +00:00
|
|
|
image = Image.open(inp).convert("RGBA")
|
2021-10-30 23:31:46 +00:00
|
|
|
|
|
|
|
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))
|
2021-11-01 22:53:48 +00:00
|
|
|
if existing[:3] == replace[:3]:
|
2021-10-30 23:31:46 +00:00
|
|
|
image.putpixel((x,y), c)
|
|
|
|
else:
|
|
|
|
image.putpixel((x,y), c)
|
|
|
|
|
2021-11-01 22:53:48 +00:00
|
|
|
frames.append(image.convert("P"))
|
2021-10-30 23:31:46 +00:00
|
|
|
|
|
|
|
|
2021-11-01 22:53:48 +00:00
|
|
|
frames[0].save(filename, mode="P", format="GIF", append_images=frames[1:], save_all=True, duration=100, loop=0)
|
2021-10-30 23:31:46 +00:00
|
|
|
|
2022-11-29 13:39:17 +00:00
|
|
|
make("dist/images/bg.gif", colors)
|
|
|
|
make("dist/images/remotecontrol.gif", colors2, inp="images/remotecontrol-small.png")
|
2021-10-30 23:31:46 +00:00
|
|
|
|
|
|
|
|