There's no easy way to do a fill_solid() but as a gradient along a

There’s no easy way to do a fill_solid() but as a gradient along a string, is there?

There’s the fill_rainbow and fill_spectrum functions, will they do what you want?

I need one single color on the whole string, but as a gradient. I can do a for loop and step through an increasing HSV value, but I was hoping there was another way. What I’m trying to do is have a string that has a random hue fade from black at leds[0] to full brightness at leds[NUM_LEDS], and have the whole string fade on and off. So for the on/off fading I’m doing a for loop that increases/decreases the HSV value. That works when using fill_solid() since all the pixels have the same value. But I don’t know how I would do that if they have different values. Fading to off would work, but not coming on.

I wrote this little function to deal with this type of situation and for fading in/out a single pixel between varying colors: https://gist.github.com/gerstle/9417780

Doesn’t do exactly what you want, but if you pass in CRGB::Black and your desired color and an increasing numerator for each pixel (denominator could just be the pixel count), it will return a CRGB that is the next step in the gradient.

This is admittedly not an efficient function and I’d love to see a better way of doing this…

Start with the Hue you want at the end, then step down the V (brightness for as many steps as you want as you push the main light down? I use a gamma correction on brightness.

Something like the following?

void gradient file(int delayconst)
{
long delay = millis()+delayconst
byte bright=255;
byte idx = 0;
leds[idx].setHue(x);
while(idx<num_leds)
{
if(delay<millis())
{
leds.show();
delay=millis()+delayconst;
led[i]=led[i-1];
bright-=255/num_leds;
led[i-1].setHSV(x,255,gamma(bright));
i++;
}

}
}

It has to fill the entire string at the same time, while stepping through a full string fade, up then down. No delays, anywhere.

fade the whole strip in steps equal to the number of leds and then after the fade move the bright LED in the direction you want to go… requires you keep brightness and hue queue.
i=0;
int direction=1;
void gradientfill(hue x)
{
if(i==num_leds){direction=-1;}
if(i==0){direction=1;}
fade_entire_strip(num_leds);
leds[i]setHue(x);
Hueq[i]=x;
BrightQ[i]=255;
i+=direction;

}

void fade_entire_strip(uint8_t fadesteps)
{
for(byte i=0;i<NUM_LEDS;i++)
{
if(leds[i]||(BrightQ[i]<=(255/fadesteps)))
{
BrightQ[i]=BrightQ[i]-(255/fadesteps); //decrement brightness
leds[i].setHSV(HueQ[i],MAX,exp_gamma[BrightQ[i]]); //show it!
}else
{
BrightQ[i]=0; //clear bright queue
HueQ[i]=0; //clear hue queue
leds[i]=0; //clear led
}

}
}

Justin, what does your gamma correction function look like?