I have a program that creates a linear gradient but uses numpy arrays. This cannot be used because the numpy library takes up too much space on the microcontroller. Is there a way to replace the numpy.array with something else?
import numpy as np
def colorFade(c1, c2, mix=0):
c1 = np.array(c1)
c2 = np.array(c2)
print(tuple((1-mix)*c1 + mix*c2))
c1 = (0, 0, 200)
c2 = (200, 0, 200)
n = 500
for x in range(n+1):
colorFade(c1,c2,x/n)
I attempted to change the array to a tuple and a list but both failed and gave this error:
TypeError: can't multiply sequence by non-int of type 'float'
The numpy.array module does not give this error.
>Solution :
Lists and tuples don’t automatically apply arithmetic operations to each element, you have to write that explicitly.
def colorFade(c1, c2, mix=0):
print(tuple((1-mix)*e1 + mix*e2 for e1, e2 in zip(c1, c2)))