// ===============================================================================
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// MeG's stripes
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// ===============================================================================

// #define TYP_MEGSTRIPE_STRIPE300_EMUL
#define TYP_MEGSTRIPE_STRIPE300_EMUL__ADADRUIT_NEO
// #define TYP_MEGSTRIPE_STRIPE300

// - - - - - indicator
#define PIN_INDY 2
#define NUM_LEDS 41

const int nW = 8;
const int nH = 35;

static byte mtx[nH][nW][3];

/*
// -=-=-=-=- microLED - arduino/AVR only!
// #include <FastLEDsupport.h>
#define COLOR_DEBTH 3
#include <microLED.h>

#define inverse  false // set to true to invert display pixel color
#define contrast 0xB2 // default is 0xBF set in LCDinit, Try 0xB1 <-> 0xBF if your display is too dark
#define bias 0x13 // LCD bias mode 1:48: Try 0x12 or 0x13 or 0x14
#define FontNumber 1 // 1-9, 1 is default, Comment in defines at top of NOKIA5110_TEXT.h if using non default

microLED<NUM_LEDS, 13, MLED_NO_CLOCK, LED_WS2818, ORDER_GRB, CLI_AVER> strip1;
*/

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - lib/vars for TYP_MEGSTRIPE_STRIPE300_EMUL
#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__FASTLED
// #define FASTLED_RMT_BUILTIN_DRIVER 1
#include <FastLED.h>

CRGB leds1[NUM_LEDS];
CRGB leds2[NUM_LEDS];
CRGB leds3[NUM_LEDS];
CRGB leds4[NUM_LEDS];
CRGB leds5[NUM_LEDS];
CRGB leds6[NUM_LEDS];
CRGB leds7[NUM_LEDS];
CRGB leds8[NUM_LEDS];

#endif
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - lib/vars for TYP_MEGSTRIPE_STRIPE300_EMUL
#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__ADADRUIT_NEO

#include <Adafruit_NeoPixel.h>

#define NUM_STRIPES 8
Adafruit_NeoPixel goaN[NUM_STRIPES] = {
  Adafruit_NeoPixel(NUM_LEDS, 13, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_LEDS, 12, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_LEDS, 14, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_LEDS, 27, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_LEDS, 26, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_LEDS, 25, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_LEDS, 33, NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_LEDS, 32, NEO_GRB + NEO_KHZ800)
};

/*
Adafruit_NeoPixel gStrip1 = Adafruit_NeoPixel(NUM_LEDS, 13, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel gStrip2 = Adafruit_NeoPixel(NUM_LEDS, 12, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel gStrip3 = Adafruit_NeoPixel(NUM_LEDS, 14, NEO_GRB + NEO_KHZ800);
*/
#endif


// ===============================================================================
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
void setup() {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - lib/vars for TYP_MEGSTRIPE_STRIPE300_EMUL
#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__FASTLED
  // !! BUGGY !!!
  FastLED.setBrightness(255);
  FastLED.setDither(BINARY_DITHER);
  FastLED.clear();

  FastLED.addLeds<WS2812, 13, GRB>(leds1, NUM_LEDS);  // GRB ordering is assumed
  // pinMode(13, OUTPUT);
  FastLED.addLeds<WS2812B, 12, GRB>(leds2, NUM_LEDS);  // GRB ordering is assumed
  // FastLED.addLeds<NEOPIXEL, 12>(leds2, NUM_LEDS);  // GRB ordering is assumed
  // FastLED.addLeds<NEOPIXEL, 12>(leds2, NUM_LEDS).setCorrection( TypicalLEDStrip );  // GRB ordering is assumed
  // pinMode(12, OUTPUT);
  FastLED.addLeds<WS2812B, 14, GRB>(leds3, NUM_LEDS);  // GRB ordering is assumed
  // pinMode(14, OUTPUT);
  // FastLED.addLeds<NEOPIXEL, 27>(leds4, NUM_LEDS);  // GRB ordering is assumed
  // FastLED.addLeds<NEOPIXEL, 26>(leds5, NUM_LEDS);  // GRB ordering is assumed
  // FastLED.addLeds<NEOPIXEL, 25>(leds6, NUM_LEDS);  // GRB ordering is assumed
  // FastLED.addLeds<NEOPIXEL, 33>(leds7, NUM_LEDS);  // GRB ordering is assumed
  // FastLED.addLeds<NEOPIXEL, 32>(leds8, NUM_LEDS);  // GRB ordering is assumed
  // FastLED.addLeds<SM16703, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<TM1829, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<TM1812, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<UCS1904, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<UCS2903, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
  // FastLED.addLeds<WS2852, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
  // FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
  // FastLED.addLeds<GS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<SK6812, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
  // FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<APA106, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<PL9823, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<WS2813, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<WS2811_400, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<GE8822, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<LPD1886, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<LPD1886_8BIT, DATA_PIN, RGB>(leds, NUM_LEDS);
  // ## Clocked (SPI) types ##
  // FastLED.addLeds<LPD6803, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
  // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
  // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<WS2803, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
  // FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
  // FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
  // FastLED.addLeds<SK9822, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical

    FastLED.setBrightness(255);
    FastLED.setDither(BINARY_DITHER);
    FastLED.clear();

#endif

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - lib/vars for TYP_MEGSTRIPE_STRIPE300_EMUL
#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__ADADRUIT_NEO
  
  for (int i=0; i<NUM_STRIPES; i++) {
    goaN[i].begin();
    goaN[i].show();
  }
#endif



} // setup

// ===============================================================================
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// ML functions

// - - - show (visualize stripes)
void ML_StripesShow() {

#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__ADADRUIT_NEO 
  for (int i=0; i<NUM_STRIPES; i++) {
    goaN[i].show();
  }
#endif

}

// - - - clean stripes
/*
void ML_StripesClear() {

#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__ADADRUIT_NEO 
  for (int i=0; i<NUM_STRIPES; i++) {
    goaN[i].show();
  }
#endif

}
*/


// ===============================================================================
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// stripes test functions
void StripeTest_DrawBlackAtIndex(int nIndex) {

#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__FASTLED
  leds1[nIndex] = CRGB::Black;
  leds2[nIndex] = CRGB::Black;
  leds3[nIndex] = CRGB::Black;
  leds4[nIndex] = CRGB::Black;
  leds5[nIndex] = CRGB::Black;
  leds6[nIndex] = CRGB::Black;
  leds7[nIndex] = CRGB::Black;
  leds8[nIndex] = CRGB::Black;
#endif
#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__ADADRUIT_NEO
  for (int i=0; i<NUM_STRIPES; i++)  {
    // for (int j=0; i<NUM_STRIPES; i++)  {
      goaN[i].setPixelColor(nIndex, 0);
    // }
  }
#endif
}

// - - - 
void StripeTest_DrawColorAtIndex(int nIndex) {

#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__FASTLED
  leds1[nIndex] = CRGB::Maroon;
  leds2[nIndex] = CRGB::Magenta;
  leds3[nIndex] = CRGB::Navy;
  leds4[nIndex] = CRGB::Lime;
  leds5[nIndex] = CRGB::DarkOliveGreen;
  leds6[nIndex] = CRGB::Cyan;
  leds7[nIndex] = CRGB::Yellow;
  leds8[nIndex] = CRGB::Azure;
#endif
#ifdef TYP_MEGSTRIPE_STRIPE300_EMUL__ADADRUIT_NEO
  goaN[0].setPixelColor(nIndex, goaN[0].Color(127,0,0));
  goaN[1].setPixelColor(nIndex, goaN[0].Color(127,0,127));
  goaN[2].setPixelColor(nIndex, goaN[0].Color(0,0,127));
  goaN[3].setPixelColor(nIndex, goaN[0].Color(0,255,0));
  goaN[4].setPixelColor(nIndex, goaN[0].Color(63,127,0));
  goaN[5].setPixelColor(nIndex, goaN[0].Color(0,127,127));
  goaN[6].setPixelColor(nIndex, goaN[0].Color(127,127,0));
  goaN[7].setPixelColor(nIndex, goaN[0].Color(163,163,215));
#endif
}

// - - - 
void StripeTest_Index() {

  static int nIndex = 0;

  StripeTest_DrawBlackAtIndex(nIndex);
  nIndex++;
  if (nIndex >= NUM_LEDS) nIndex = 0;
  StripeTest_DrawColorAtIndex(nIndex);
  ML_StripesShow();
}

// - - - 
void StripeTest_Fill() {
  for (int i=0; i<NUM_LEDS; i++) {
    StripeTest_DrawBlackAtIndex(i);
  }
  ML_StripesShow();
  delay(300);
  
  for (int i=0; i<NUM_LEDS; i++) {
    StripeTest_DrawColorAtIndex(i);
  }
  ML_StripesShow();
  delay(300);
}


// ===============================================================================
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// mtx functions
void ML_SetColorMtx(int x, int y, byte r, byte g, byte b, bool isMix = false) {

  if ((x < 0) or (x >= nW)) return;
  if ((y < 0) or (y >= nH)) return;

  int c;
  c = r + (isMix ? mtx[y][x][0] : 0);
  mtx[y][x][0] = (c > 0xff) ? 0xff : c;
  c = g + (isMix ? mtx[y][x][0] : 0);
  mtx[y][x][1] = (c > 0xff) ? 0xff : c;
  c = b + (isMix ? mtx[y][x][0] : 0);
  mtx[y][x][2] = (c > 0xff) ? 0xff : c;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
void ML_RenderMtx() {

  for (int iH = 0; iH < nH; iH++) {
    for (int iW = 0; iW < nW; iW++) {
      // mlSetColor(iW, iH, CRGB( mtx[iH][iW][0], mtx[iH][iW][1], mtx[iH][iW][2]) );
    // goaN[iW].setPixelColor(iH, goaN[0].Color(mtx[iH][iW][0], mtx[iH][iW][1], mtx[iH][iW][2]));
    goaN[iW].setPixelColor(iH, mtx[iH][iW][0] << 16 | mtx[iH][iW][1] << 8 | mtx[iH][iW][2]);
    }
  }

}



// ===============================================================================
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// MeG LEDS300 Effects
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// ===============================================================================
void MeG_LEDS300_RelictFill() {

  for (int iH = 0; iH < nH; iH++) {
    for (int iW = 0; iW < nW; iW++) {

      ML_SetColorMtx(iW, iH, 0, 0, 0);
      // ML_SetColorMtx(iW, iH, 7, 5, 3);
      // leds1[i] = CRGB(7, 5, 3);
      // leds1[i] = CRGB(17,15,13);
      // static int cbg = 0;
      // cbg = 1.1*sin((f1+i/20))*63+63;
      // leds1[i] = CRGB( cbg+7, cbg+5, cbg+3);

    }
  }

}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
void MeG_LEDS300_theWall() {
  static float fOfs = 0;
  static float r = 7;
  static int y = 0;
  static float yt = 0;
  fOfs += .009;

  // cleanup mtx
  /*
  for (int iH = 0; iH < nH; iH++) {
    for (int iW = 0; iW < nW; iW++) {
      mtx[iH][iW][0] = 0;
      mtx[iH][iW][1] = 0;
      mtx[iH][iW][2] = 0;
    }
  }
  */

// oceonize
/*
  float c;
  for (int iH = 0; iH < nH; iH++) {
    for (int iW = 0; iW < nW; iW++) {
      c = 14 * abs(sin(fOfs + iH))  + 3 * abs(cos(fOfs + iW));
      // c = 10;
      mtx[iH][iW][0] = c;
      mtx[iH][iW][1] = c;
      mtx[iH][iW][2] = c;
    }
  }
  */
    for (y = -r; y <= r; y++) {
      float cp = 20 + (cos(y / 2.5) * r) * 2;
      // float cp = 130+y*10;

      yt = nH / 2 + y + (sin(fOfs) * nH);
      for (int i = 0; i < nW; i++) {
        ML_SetColorMtx(i, yt, 0, int (cp / 1.5), 0);
      }

      yt = nH / 2 + y + (sin(fOfs * 1.2) * nH) + 2;
      for (int i = 0; i < nW; i++) {
        ML_SetColorMtx(i, yt, int (cp / 1.5), 0, 0);
      }

      yt = nH / 2 + y + (sin(fOfs * 1.7) * nH) + 2;
      for (int i = 0; i < nW; i++) {
        ML_SetColorMtx(i, yt, 0, 0, int (cp / 1.5));
      }
  
    }
  /*
      for (int i = 0; i < nW; i++) {
        mlSetColorMtx(i, 10, 0, 0, 200);
      }
  */

/*
  // render
  for (int iH = 0; iH < nH; iH++) {
    for (int iW = 0; iW < nW; iW++) {
      mlSetColor(iW, iH, CRGB( mtx[iH][iW][0], mtx[iH][iW][1], mtx[iH][iW][2]) );
    }
  }
*/


}



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
void MeG_LEDS300_theBall(float f1, float f2, int cr, int cg, int cb) {

  int r = 1.5;
  int y = nH / 2 + sin(f1) * (nH / 2);
  int x = nW / 2 + cos(f2) * (nW / 2);

/*
  CRGB c = CRGB(cr, cg, cb);
  CRGB c2 = CRGB(cr / 16, cg / 16, cb / 16);
  CRGB c3 = CRGB(cr / 20, cg / 20, cb / 20);
  */

  ML_SetColorMtx(x, y, cr, cg, cb);


  ML_SetColorMtx(x + 1, y, cr / 20, cg / 20, cb / 20);
  ML_SetColorMtx(x - 1, y, cr / 20, cg / 20, cb / 20);


  ML_SetColorMtx(x, y + 1, cr / 16, cg / 16, cb / 16);
  ML_SetColorMtx(x, y - 1, cr / 16, cg / 16, cb / 16);

  ML_SetColorMtx(x, y - 2, cr / 20, cg / 20, cb / 20);
  ML_SetColorMtx(x, y + 2, cr / 20, cg / 20, cb / 20);

/*
  mlSetColor(x + 1, y, c3);
  mlSetColor(x - 1, y, c3);

  mlSetColor(x, y + 1, c2);
  mlSetColor(x, y - 1, c2);

  mlSetColor(x, y - 2, c3);
  mlSetColor(x, y + 2, c3);
*/

  /*
      mlSetColor(x+1, y-2, c3);
      mlSetColor(x+1, y+2, c3);
      mlSetColor(x-1, y-2, c3);
      mlSetColor(x-1, y+2, c3);
  */
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
#define SNAKE_LEN 9

void MeG_LEDS300_theSnake(bool __isFirstRun = false) {
    static int aSnake[SNAKE_LEN][2];
    static int nHead = 0;  // head position

    if (__isFirstRun) {
      for (int i=0; i<SNAKE_LEN; i++) {
        aSnake[i][0] = 0;
        aSnake[i][1] = 0;
        nHead = i;
      }
    };

    // - - - move the snake
    static float x = 0;
    static float y = 4;
    static float xi = 1;
    static float yi = 1;

    static float yr = 0.7;
    static float yk = 0.2;
    static float yki = 0.3;

    nHead++;
    if (nHead >= SNAKE_LEN) nHead = 0;

    x += xi;
    if (x > nW-1) {
      x = nW-1;
      xi = -xi;
    }
    if (x < 0) {
      x = 0;
      xi = -xi;
    }
    y += yi+sin(yk)*yr;
    yk += yki;
    if (y > nH-1) {
      y = nH-1;
      yi = -yi;
    }
    if (y < 0) {
      y = 0;
      yi = -yi;
    }
    aSnake[nHead][0] = int(x);
    aSnake[nHead][1] = int(y);


    // - - - draw the snake
    int nPos = nHead;
    for (int i=0; i<SNAKE_LEN; i++) {
      nPos++; // drawing from tail
      if (nPos >= SNAKE_LEN) nPos = 0;

      byte c = 5+i*6;
      ML_SetColorMtx(aSnake[nPos][0], aSnake[nPos][1], c, c, c);

    }


}


// ===============================================================================
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

static uint8_t cl1[1890] = {
131, 89, 45, 136, 93, 44, 138, 
97, 46, 130, 94, 50, 140, 94, 42, 153, 
117, 58, 143, 111, 58, 132, 92, 43, 122, 
85, 44, 93, 66, 33, 72, 45, 19, 93, 
62, 29, 118, 80, 37, 120, 88, 38, 131, 
97, 42, 128, 94, 43, 115, 86, 39, 128, 
98, 48, 128, 100, 53, 129, 103, 57, 138, 
118, 74, 132, 92, 49, 136, 94, 45, 141, 
101, 49, 132, 97, 51, 145, 99, 45, 159, 
125, 67, 143, 114, 61, 79, 62, 44, 28, 
23, 20, 22, 16, 12, 18, 15, 13, 19, 
16, 14, 47, 39, 29, 115, 92, 57, 130, 
96, 43, 129, 97, 45, 126, 98, 48, 133, 
103, 51, 131, 104, 58, 133, 109, 63, 140, 
119, 72, 137, 99, 55, 139, 97, 49, 136, 
88, 41, 135, 95, 47, 150, 106, 50, 159, 
127, 71, 79, 60, 30, 28, 19, 14, 45, 
26, 16, 67, 48, 35, 55, 40, 30, 50, 
40, 34, 61, 56, 49, 90, 90, 81, 135, 
117, 89, 129, 98, 46, 121, 92, 44, 130, 
98, 48, 134, 106, 61, 133, 112, 68, 141, 
118, 73, 133, 97, 55, 140, 97, 48, 137, 
86, 39, 140, 97, 49, 154, 114, 57, 103, 
78, 42, 11, 6, 5, 41, 24, 14, 57, 
35, 23, 110, 84, 63, 156, 137, 117, 117, 
102, 90, 114, 103, 90, 141, 140, 131, 152, 
160, 161, 137, 119, 90, 120, 90, 43, 127, 
93, 49, 133, 105, 60, 135, 113, 69, 147, 
126, 85, 133, 97, 56, 140, 94, 46, 140, 
90, 41, 138, 94, 47, 139, 98, 48, 24, 
14, 7, 18, 9, 6, 42, 20, 11, 55, 
33, 22, 114, 90, 71, 174, 163, 150, 184, 
180, 173, 158, 148, 139, 151, 146, 136, 156, 
165, 169, 149, 152, 145, 121, 91, 47, 126, 
94, 50, 134, 105, 62, 134, 109, 67, 149, 
128, 86, 144, 106, 64, 139, 90, 44, 145, 
95, 44, 138, 95, 45, 118, 77, 37, 10, 
7, 6, 29, 13, 8, 44, 26, 18, 61, 
44, 36, 115, 96, 84, 165, 159, 152, 157, 
152, 148, 150, 144, 140, 163, 154, 147, 150, 
156, 157, 136, 143, 141, 118, 86, 46, 124, 
91, 50, 143, 120, 79, 130, 101, 61, 147, 
126, 86, 139, 99, 57, 139, 91, 45, 145, 
93, 43, 139, 93, 45, 101, 65, 31, 13, 
8, 6, 39, 20, 14, 42, 27, 22, 44, 
28, 22, 84, 61, 52, 181, 181, 181, 126, 
119, 116, 138, 129, 123, 179, 181, 182, 137, 
133, 128, 93, 92, 84, 124, 98, 72, 124, 
90, 52, 139, 116, 77, 132, 98, 56, 139, 
114, 76, 138, 95, 51, 137, 89, 47, 143, 
90, 42, 141, 95, 51, 97, 64, 32, 18, 
8, 6, 46, 25, 19, 45, 37, 35, 41, 
37, 37, 64, 36, 28, 195, 195, 197, 61, 
43, 41, 83, 86, 93, 184, 186, 189, 165, 
164, 162, 66, 57, 46, 121, 95, 70, 125, 
91, 52, 129, 98, 60, 133, 100, 58, 133, 
106, 72, 145, 100, 54, 138, 89, 46, 143, 
88, 39, 142, 94, 47, 79, 52, 27, 31, 
13, 9, 48, 23, 16, 39, 23, 19, 31, 
14, 10, 82, 49, 41, 202, 192, 190, 161, 
152, 150, 150, 131, 126, 200, 191, 191, 206, 
205, 206, 78, 71, 66, 116, 84, 56, 128, 
92, 53, 131, 92, 52, 137, 103, 61, 140, 
110, 71, 138, 93, 47, 139, 91, 49, 147, 
94, 42, 138, 88, 42, 73, 49, 25, 40, 
18, 11, 72, 31, 20, 88, 46, 38, 59, 
25, 17, 105, 65, 59, 190, 171, 173, 197, 
182, 184, 167, 122, 120, 212, 201, 207, 214, 
211, 213, 172, 158, 160, 149, 108, 93, 130, 
90, 50, 126, 84, 43, 138, 102, 59, 145, 
110, 69, 144, 99, 55, 106, 59, 33, 143, 
92, 46, 138, 89, 44, 80, 51, 26, 39, 
17, 10, 83, 38, 28, 86, 40, 34, 54, 
23, 18, 86, 58, 57, 178, 162, 165, 195, 
191, 195, 126, 88, 87, 199, 181, 186, 207, 
198, 198, 187, 148, 147, 130, 96, 70, 130, 
88, 49, 130, 89, 50, 143, 101, 56, 147, 
107, 62, 143, 97, 53, 110, 64, 35, 132, 
77, 39, 142, 90, 46, 85, 49, 26, 33, 
12, 7, 78, 37, 28, 82, 42, 34, 59, 
27, 23, 93, 62, 62, 166, 109, 127, 196, 
169, 187, 166, 159, 159, 200, 189, 189, 210, 
202, 201, 176, 155, 158, 121, 82, 51, 129, 
86, 47, 128, 85, 45, 145, 97, 51, 150, 
102, 52, 135, 85, 44, 126, 74, 41, 123, 
70, 37, 133, 77, 41, 123, 76, 42, 62, 
31, 18, 74, 36, 26, 84, 45, 36, 62, 
32, 25, 88, 49, 49, 162, 118, 129, 207, 
201, 208, 196, 196, 198, 210, 207, 207, 171, 
162, 160, 129, 110, 103, 119, 75, 43, 133, 
89, 50, 134, 87, 47, 145, 94, 49, 152, 
101, 52, 135, 87, 45, 130, 76, 41, 125, 
70, 39, 124, 67, 35, 125, 77, 42, 99, 
58, 31, 69, 36, 22, 83, 44, 38, 73, 
37, 29, 91, 61, 57, 173, 149, 150, 206, 
205, 209, 212, 212, 213, 195, 194, 196, 145, 
142, 146, 119, 97, 85, 125, 81, 48, 137, 
93, 53, 129, 81, 42, 145, 92, 48, 152, 
98, 51, 130, 83, 43, 122, 65, 33, 123, 
67, 36, 112, 62, 35, 91, 56, 37, 59, 
37, 32, 42, 24, 23, 64, 35, 32, 92, 
54, 51, 94, 47, 44, 166, 123, 130, 205, 
199, 203, 194, 193, 193, 171, 166, 166, 135, 
132, 139, 178, 199, 213, 165, 169, 169, 142, 
104, 78, 130, 77, 42, 139, 87, 46, 148, 
89, 46, 130, 79, 41, 112, 60, 34, 100, 
71, 53, 83, 63, 54, 88, 69, 68, 83, 
64, 66, 69, 50, 51, 49, 24, 21, 85, 
50, 47, 101, 62, 61, 143, 114, 115, 189, 
185, 189, 192, 192, 192, 140, 126, 127, 120, 
106, 109, 159, 171, 183, 185, 208, 227, 193, 
218, 231, 148, 124, 109, 134, 77, 42, 145, 
84, 44, 118, 65, 32, 102, 73, 61, 103, 
92, 88, 112, 114, 123, 127, 132, 149, 119, 
125, 143, 108, 97, 103, 61, 44, 45, 87, 
51, 48, 101, 62, 60, 146, 128, 128, 186, 
184, 186, 144, 131, 131, 127, 113, 122, 122, 
102, 106, 159, 172, 190, 169, 196, 217, 189, 
225, 247, 207, 234, 237, 139, 82, 49, 146, 
85, 45, 110, 69, 48, 100, 81, 74, 120, 
122, 135, 138, 147, 167, 163, 177, 200, 165, 
186, 217, 143, 149, 170, 114, 115, 128, 86, 
48, 44, 107, 63, 61, 123, 90, 88, 114, 
88, 86, 91, 75, 78, 114, 96, 103, 118, 
106, 117, 114, 105, 113, 158, 187, 214, 174, 
208, 232, 208, 243, 252, 179, 184, 182, 140, 
81, 46, 112, 89, 82, 105, 90, 88, 124, 
126, 143, 145, 159, 181, 176, 192, 211, 182, 
209, 236, 161, 173, 198, 177, 187, 210, 130, 
94, 90, 113, 77, 72, 72, 35, 33, 59, 
25, 23, 109, 92, 98, 105, 83, 89, 126, 
121, 135, 126, 127, 142, 131, 147, 170, 165, 
192, 210, 192, 225, 241, 208, 242, 252, 164, 
154, 147, 111, 85, 80, 119, 111, 115, 106, 
87, 90, 150, 165, 186, 181, 199, 216, 174, 
198, 227, 158, 170, 194, 192, 210, 229, 152, 
124, 125, 117, 78, 72, 67, 33, 30, 99, 
79, 86, 113, 95, 101, 102, 78, 83, 143, 
145, 164, 127, 127, 145, 107, 99, 108, 160, 
184, 205, 188, 219, 238, 196, 223, 237, 148, 
114, 99, 99, 53, 26, 102, 82, 84, 111, 
102, 109, 127, 128, 145, 175, 197, 216, 150, 
166, 196, 137, 141, 164, 157, 160, 182, 162, 
161, 170, 92, 55, 53, 88, 69, 78, 141, 
140, 159, 107, 89, 95, 103, 76, 80, 141, 
139, 157, 112, 100, 108, 121, 120, 136, 158, 
177, 200, 193, 218, 235, 171, 134, 115, 150, 
95, 55, 97, 52, 28, 95, 52, 32, 63, 
45, 49, 115, 104, 113, 153, 156, 163, 124, 
137, 159, 147, 115, 92, 121, 108, 119, 150, 
154, 170, 151, 166, 184, 167, 186, 210, 119, 
115, 128, 107, 95, 103, 101, 76, 79, 130, 
127, 145, 89, 71, 78, 113, 99, 109, 161, 
164, 182, 195, 178, 168, 170, 119, 76, 156, 
104, 59, 96, 53, 28, 104, 71, 61, 60, 
51, 49, 160, 96, 38, 190, 142, 63, 120, 
66, 34, 92, 70, 74, 143, 118, 97, 101, 
94, 93, 138, 164, 200, 137, 152, 180, 104, 
98, 112, 101, 95, 104, 90, 68, 72, 133, 
140, 157, 63, 59, 69, 61, 30, 26, 148, 
116, 105, 196, 175, 164, 162, 110, 64, 160, 
107, 60, 92, 55, 41, 119, 125, 133, 66, 
61, 62, 145, 72, 21, 145, 67, 28, 190, 
116, 55, 68, 36, 51, 181, 153, 113, 158, 
125, 79, 131, 154, 177, 130, 150, 182, 88, 
87, 103, 84, 80, 92, 84, 70, 77, 129, 
141, 164, 53, 44, 51, 56, 26, 22, 150, 
118, 108, 196, 173, 163, 167, 125, 92, 151, 
95, 53, 50, 87, 132, 117, 129, 131, 82, 
101, 113, 89, 97, 117, 132, 136, 142, 124, 
122, 124, 114, 142, 158, 219, 233, 228, 211, 
226, 220, 199, 224, 238, 136, 166, 204, 86, 
92, 109, 73, 69, 83, 87, 80, 92, 115, 
129, 154, 108, 126, 139, 50, 24, 19, 149, 
116, 105, 195, 175, 166, 198, 198, 188, 144, 
117, 100, 26, 43, 66, 94, 86, 83, 151, 
158, 145, 157, 183, 184, 181, 213, 223, 191, 
225, 235, 199, 228, 232, 209, 232, 231, 221, 
243, 246, 182, 204, 220, 116, 146, 188, 82, 
91, 111, 73, 69, 83, 74, 70, 79, 111, 
129, 159, 123, 148, 166, 40, 18, 16, 139, 
108, 96, 192, 170, 159, 180, 173, 162, 139, 
132, 125, 57, 24, 15, 75, 47, 35, 114, 
86, 60, 132, 126, 108, 154, 168, 160, 170, 
191, 188, 192, 215, 212, 209, 230, 232, 225, 
245, 247, 183, 203, 215, 142, 152, 177, 120, 
103, 120, 109, 59, 51, 116, 67, 59, 131, 
99, 109, 136, 109, 113, 123, 60, 28, 157, 
101, 64, 185, 142, 113, 184, 155, 138, 173, 
130, 101, 119, 49, 19, 121, 53, 26, 105, 
78, 60, 112, 102, 88, 139, 150, 144, 167, 
188, 186, 192, 217, 220, 206, 230, 233, 223, 
241, 243, 157, 136, 129, 136, 74, 43, 146, 
75, 38, 151, 75, 34, 160, 88, 46, 167, 
102, 58, 166, 97, 48, 176, 108, 53, 184, 
121, 62, 184, 120, 58, 180, 115, 50, 175, 
113, 51, 111, 44, 17, 106, 42, 17, 97, 
68, 53, 106, 94, 81, 127, 131, 120, 158, 
175, 167, 192, 212, 210, 210, 230, 230, 225, 
242, 242, 171, 203, 222, 135, 140, 157, 129, 
61, 36, 136, 61, 28, 146, 71, 34, 152, 
78, 39, 155, 82, 40, 157, 90, 49, 165, 
105, 60, 166, 104, 55, 165, 95, 42, 168, 
101, 46, 84, 53, 56, 134, 174, 199, 140, 
170, 186, 102, 88, 73, 115, 109, 91, 160, 
172, 162, 193, 212, 208, 212, 230, 229, 227, 
244, 243, 219, 195, 169, 198, 223, 233, 162, 
197, 219, 131, 87, 83, 141, 75, 39, 148, 
83, 45, 149, 87, 49, 155, 95, 57, 159, 
105, 65, 165, 107, 63, 161, 134, 131, 163, 
140, 135  
  };


void MeG_LEDS300_ImgCrop(float f1, float f2) {

  static int w = 21;
  static int h = 30;
  int xOfs = (w-nW)/2 + sin(f1) * (w-nW)/2;
  int yOfs = (w-nH)/2 + sin(f1) * (w-nH)/2;


  for (int iH = 0; iH < nH; iH++) {
    for (int iW = 0; iW < nW; iW++) {

      int nOfs = 21*3*(iH+xOfs)+(iW+yOfs)*3;
      ML_SetColorMtx(iW, iH, cl1[nOfs] /4, cl1[nOfs+1] /4, cl1[nOfs+2] /4);
      // ML_SetColorMtx(iW, iH, 7, 5, 3);
      // leds1[i] = CRGB(7, 5, 3);
      // leds1[i] = CRGB(17,15,13);
      // static int cbg = 0;
      // cbg = 1.1*sin((f1+i/20))*63+63;
      // leds1[i] = CRGB( cbg+7, cbg+5, cbg+3);

    }
  }

}


// ===============================================================================
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

static int nIters = 0;

void loop() {

  // first iteration
  if (!nIters)  {
    MeG_LEDS300_theSnake(true);
  }
  nIters++;
  

  // tests
  /*
  StripeTest_Fill();
  */
  // StripeTest_Index();

  //  - - - - - LEDS300
  static float f1 = 0;
  static float f2 = 0;
  f1 += 0.057 / 1.3;
  f2 += 0.072 / 1.3;

  MeG_LEDS300_RelictFill();
  
  MeG_LEDS300_theWall();

  static byte ca = 255;
  static byte cp = 0;
  MeG_LEDS300_theBall(f1, f2, ca, cp, cp);
  MeG_LEDS300_theBall(f1 + 2.2, f2 + 1.2, cp, ca, cp);
  MeG_LEDS300_theBall(f1 + 0.8, f2 + 0.8, cp, cp, ca);

  MeG_LEDS300_theSnake();

  // MeG_LEDS300_ImgCrop(f1, f2);

  ML_RenderMtx();

/*
  byte b = rand()*13 & 0x0f;
  goaN[3].setPixelColor(b, goaN[0].Color(0,255,0)); 
  b = rand()*13 & 0x0f;
  goaN[3].setPixelColor(b, goaN[0].Color(127,0,0)); 
*/
  ML_StripesShow();

  // delay(50);
}




FPS: 0
Power: 0.00W