How would I write a function that would take two colors: (255,0,0), and (0,0,255), a value from 0.0 to 1.0, and have it output the color in between the first two based on that number. Like, if I ran this function like this:
gradient((255,0,0),(0,0,255),0.5)
it would return
(128,0,128)
Name:
Anonymous2010-05-05 23:30
r = r1*p+r2*(p-1);
g = g1*p+g2*(p-1);
b = b1*p+b2*(p-1);
...isn't it obvious?
Name:
Anonymous2010-05-05 23:31
>>2
fuck. try this instead r = r1*p+r2*(1-p);
g = g1*p+g2*(1-p);
b = b1*p+b2*(1-p);
Name:
Anonymous2010-05-05 23:48
>>3 gradient = lambda c1, c2, pos: [int(n * pos + m * (1 - pos)) for m, n in zip(c1, c2)]