如果你有steps = 200
和(200, 180, 230)
然后用
step_R = 200/steps
step_G = 180/steps
step_B = 230/steps
然后Color(int(step_R*b), int(step_G*b), int(step_B*b))
未测试:
destination = (200, 180, 230)
steps = 200
step_R = destination[0]/steps
step_G = destination[1]/steps
step_B = destination[2]/steps
for x in range(steps):
r = int(step_R*x)
g = int(step_G*x)
b = int(step_B*x)
c = Color(r, g, b)
for i in range(strip.numPixels()):
strip.setPixelColor(i, c)
strip.show()
time.sleep(wait_ms/1000.0)
for x in range(steps, -1, -1):
r = int(step_R*x)
g = int(step_G*x)
b = int(step_B*x)
c = Color(r, g, b)
for i in range(strip.numPixels()):
strip.setPixelColor(i, c)
strip.show()
time.sleep(wait_ms/1000.0)
可以使用r += step_R
,而不是r = int(step_R * x)
未测试:
destination = (200, 180, 230)
steps = 200
step_R = destination[0]/steps
step_G = destination[1]/steps
step_B = destination[2]/steps
r = 0
g = 0
b = 0
for x in range(steps):
c = Color(int(r), int(g), int(b))
for i in range(strip.numPixels()):
strip.setPixelColor(i, c)
strip.show()
time.sleep(wait_ms/1000.0)
r += step_R
g += step_G
b += step_B
for x in range(steps):
r -= step_R
g -= step_G
b -= step_B
c = Color(int(r), int(g), int(b))
for i in range(strip.numPixels()):
strip.setPixelColor(i, c)
strip.show()
time.sleep(wait_ms/1000.0)
如果有'步骤= 200'然后用'step_R = 200/steps','step_G = 180/steps','step_B = 230/steps'然后'颜色(INT(step_R * b),INT(step_G * b),INT(step_B * b))' – furas