I made a modification so the meteor go from one side, then comes back from the other. Seems like there is a tiny color glitch after the meteor came back, not sure why but it's fine anyway. Here's the code:
#include "FastLED.h"
#define NUM_LEDS 136
CRGB leds[NUM_LEDS];
#define PIN 6
void setup()
{
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop()
{
meteorRain(CRGB(0x10,0x18,0x10), CRGB(0xFF,0x11,0x26),10 ,64 ,true, 30);
meteorRainReverse(CRGB(0x10,0x18,0x10), CRGB(0xFF,0x11,0x26),10 ,64 ,true, 30);
}
void meteorRain(CRGB ColorBackground, CRGB ColorMeteor, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)
{
// set background color
fill_solid( leds, NUM_LEDS, ColorBackground );
for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++)
{
// fade color to background color for all LEDs
for(int j=0; j < NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10) > 5) ) {
leds[j] = fadeTowardColor(leds[j], ColorBackground, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j < NUM_LEDS) && (i-j >= 0) ) {
leds[i-j]= ColorMeteor;
}
}
FastLED.show();
delay(SpeedDelay);
}
}
void meteorRainReverse(CRGB ColorBackground, CRGB ColorMeteor, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)
{
// set background color
fill_solid( leds, NUM_LEDS, ColorBackground );
for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++)
{
// fade color to background color for all LEDs
for(int j=0; j < NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10) > 5) ) {
leds[j] = fadeTowardColor(leds[j], ColorBackground, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j < NUM_LEDS) && (i-j >= 0) ) {
leds[NUM_LEDS-i-j]= ColorMeteor;
}
}
FastLED.show();
delay(SpeedDelay);
}
}
// Functions from Kriegsman example
CRGB fadeTowardColor( CRGB& cur, const CRGB& target, uint8_t amount)
{
nblendU8TowardU8( cur.red, target.red, amount);
nblendU8TowardU8( cur.green, target.green, amount);
nblendU8TowardU8( cur.blue, target.blue, amount);
return cur;
}
// function used by "fadeTowardColor"
void nblendU8TowardU8( uint8_t& cur, const uint8_t target, uint8_t amount)
{
if( cur == target) return;
if( cur < target ) {
uint8_t delta = target - cur;
delta = scale8_video( delta, amount);
cur += delta;
} else {
uint8_t delta = cur - target;
delta = scale8_video( delta, amount);
cur -= delta;
}
}