LED Feature Request: generate frames to interpolate between colors.
Opened this issue · 0 comments
clintiepoo commented
@haata - here's the script I wrote FYI. It linear interpolates between the colors based on the number of steps and outputs full-keyboard frames.
import numpy as np
from scipy.interpolate import interp1d
colors = [[105,255,105]] # White
colors.append([0,0,0]) # Dark
colors.append([255,0,0]) # Red
colors.append([255,60,0]) # Orange
colors.append([255,255,0]) # Yellow
colors.append([0,255,0]) # Green
colors.append([135,135,0]) # Light Blue
colors.append([0,0,255]) # Dark Blue
colors.append([90,0,255]) # Purple
colors.append(colors[0]) # first color again - makes a loop
#Steps between color
steps = 100
# Decompose lists into individual color lists
reds = [item[0] for item in colors]
greens = [item[1] for item in colors]
blues = [item[2] for item in colors]
# X axis = array from 0 to number of colors
x = np.arange(0,len(colors))
# Interpolate Functions
f_red = interp1d(x,reds)
f_green = interp1d(x,greens)
f_blue = interp1d(x,blues)
# Generate final x values
step=1/(steps+1)
x_fin = np.arange(0,len(colors)+step-1,step)
# Write to file (overwrite)
f = open("output.txt", "w")
for x in x_fin:
red = int(f_red(x))
green = int(f_green(x))
blue = int(f_blue(x))
f.write("P[c:0%%](%s,%s,%s),P[c:100%%](%s,%s,%s);\r" % (red,green,blue,red,green,blue))
f.close()