I’m having problems with the transition from one color to another inside a for loop. c1 and c2 can be any random color - I want to be able to slide between the two inside any size for loop.
CRGB c1 = CRGB( 60, 100, 100);
CRGB c2 = CRGB( 0, 100, 100);
CRGB trans = CRGB( 0, 100, 100);
int ticks = 400;
for ( int tick = 0; tick <=400; tick++ ){
trans.r = c1.r +((c2.r - c1.r)/tickstick);
trans.g = c1.g +((c2.g - c1.g)/tickstick);
trans.b = c1.b +((c2.b - c1.b)/ticks*tick);
fill_solid(leds, NUM_LEDS, trans);
FastLED.show();
FastLED.delay(20);
// … plus more dragons in the tick loop.
}
Looks like I just had to do some casting.
trans.r = c1.r + int16_t(((c2.r - c1.r)*tick)/ticks);
I’m still interested if there is a better way to transition between 2 colors. Thanks.
Do you mean to transition from one color to another across a number of LED’s?
How about across all of the LED’s with:
fill_gradient(leds, NUM_LEDS, CHSV(50, 255,255), CHSV(100,255,255));
or how about a start/end point with:
fill_gradient_RGB(leds, startpos, 0x000011, endpos, 0x110000);
fill_gradient(leds, startpos, CHSV(50, 255,255) , endpos, CHSV(150,255,255));
or how about a DIY by doing something like the one below. This allows you to do a single transitioning color across one or many LED’s:
leds[i] = blend(CRGB::Red, CRGB::Blue, sin8(mysine));
See: http://fastled.io/docs/3.1/group___colorutils.html