#include <FastLED.h>

//FASTLED 
#define LEDstripPin 4                          
#define NUM_LEDS 196
#define COLOR_ORDER GRB
#define CHIPSET WS2812B

CRGB leds[NUM_LEDS];

bool BeatTrigger = false;

CRGBPalette16 currentPalette = LavaColors_p;

void setup() 
{
  FastLED.addLeds<WS2812B,LEDstripPin , GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(100);
  
  FastLED.setBrightness(255);                                      //FANCY STARTUP SEQUENCE TO SHOW LEDS ARE WORKING 
  for (int i = 0; i<= NUM_LEDS-1;i++)
  {
   leds[i] = CRGB::Blue;
   FastLED.show();
   delay(10);
  }
  fill_solid(leds, NUM_LEDS, CRGB( 0, 0, 0));
  FastLED.show();
  FastLED.setBrightness(255);
}


void loop() 
{
  BeatTrigger = true;
  Paintball();
}

void Paintball(){
  int randomLED = 2;//random8(0,NUM_LEDS-1);
  int randomColor = random8();
  int paintballWidth = 2;
  int paintballBrightness = 255;
  int Fadetime = 40;
  int calc = 0;
  float spreadmultiplier = 0.8;
  
  if (BeatTrigger == true ){ 
    leds[randomLED] = ColorFromPalette(currentPalette,randomColor,paintballBrightness,LINEARBLEND);
      for(int i = 1; i <= paintballWidth; i++){
          paintballBrightness = paintballBrightness*spreadmultiplier ;
        
        if (randomLED-i <= 0) {
          leds[NUM_LEDS-i] = ColorFromPalette(currentPalette,randomColor,paintballBrightness,LINEARBLEND);
        } 
        
        if(randomLED+i > NUM_LEDS-1){
           leds[i-1] = ColorFromPalette(currentPalette,randomColor,paintballBrightness,LINEARBLEND);  
           leds[randomLED-i] = ColorFromPalette(currentPalette,randomColor,paintballBrightness,LINEARBLEND);       
             
        }else{
          leds[randomLED-i] = ColorFromPalette(currentPalette,randomColor,paintballBrightness,LINEARBLEND);
          leds[randomLED+i] = ColorFromPalette(currentPalette,randomColor,paintballBrightness,LINEARBLEND);
                                                      
        }
      } 
  BeatTrigger = false;
  }
  fadeToBlackBy(leds,NUM_LEDS,Fadetime);
  FastLED.show();
}