#include <FastLED.h>

#define DATA_PIN 7
#define NUM_LEDS 12
CRGB leds[NUM_LEDS];
void setup() {
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

  // Startup Sequence
  FillLoop( CRGB::Red, 100 );
  RevFillLoop( CRGB::Navy, 100 );
  RotatingRing( 14, CRGB::Red, CRGB::Navy, 200 );
  Solid( CRGB::Black, 2000 );
}

// User Input
#define SPD 150
#define MIN 50

void loop() { 
  CRGB c1 = rcolor();
  CRGB c2 = rcolor();  
  int a = random(0,4);
  if(a == 0){ FillLoop( c1, rtime() ); }
  if(a == 1){ RevFillLoop( c1, rtime() ); }
  if(a == 2){ RotatingRing( random(0,5), c1, c2, rtime() ); }
  if(a == 3){ BlinkLoop( 1, c1, rtime() ); }
  if(a == 4){ AltFillLoop( c1, rtime() ); }
  if(a == 5){ Solid( c1, rtime() ); }
}


//////////////////////////////// HELPERS ////////////////////////////////
int rtime() {
  return random(MIN,SPD);
}
CRGB rcolor() {
  return CRGB(random(0,255), random(0,255), random(0,255));
}

//////////////////////////////// FUNCTIONS ////////////////////////////////
void Solid ( CRGB c1, int t ) {
  for (int i=0; i<NUM_LEDS; i=i+1) {
    leds[i] = c1;
  }
  FastLED.show();
  delay(t);
}

void RotatingRing ( int n, CRGB c1, CRGB c2, int t ) {
  int x=0;
  for(int j =0; j<n; j=j+1){
    for (int i=x; i<NUM_LEDS; i=i+2) {
      leds[i] = c1;
    }
    x=abs(x-1);
    for (int i=x; i<NUM_LEDS; i=i+2) {
      leds[i] = c2;
    }
    FastLED.show();
    delay(t);
  }
}

void BlinkLoop ( int n, CRGB c1, int t ) {
  for(int j =0; j<n; j=j+1){
    for(int i=0; i<NUM_LEDS; i+=1){
      leds[i] = c1;
      FastLED.show();
      delay(t);
      leds[i] = CRGB::Black;
      FastLED.show();
      delay(t);
    }
  }
}

void FillLoop ( CRGB c1, int t ) {
  for(int i=0; i<NUM_LEDS; i+=1){
    leds[i] = c1;
    FastLED.show();
    delay(t);
  }
}

void RevFillLoop ( CRGB c1, int t ) {
  for(int i=NUM_LEDS-1; i>=0; i-=1){
    leds[i] = c1;
    FastLED.show();
    delay(t);
  }
}

void AltFillLoop ( CRGB c1, int t ) {
  for(int i=0; i<NUM_LEDS; i+=3){
    leds[i] = c1;
    FastLED.show();
    delay(t);
  }
}
