// source: https://editor.soulmatelights.com/gallery/597-sin-dots

#include "FastLED.h"
#define DATA_PIN 2
#define BRIGHTNESS 255
#define NUM_LEDS 256
#define LED_COLS 16
#define LED_ROWS 16
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
//#define FRAMES_PER_SECOND 60
const uint8_t kMatrixWidth = 16;
const uint8_t kMatrixHeight = 16;

const bool    kMatrixSerpentineLayout = false;


void setup() {
  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS); //setCorrection(TypicalLEDStrip);
  //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
 //Serial.begin(115200);
}

void loop() 
{
  fadeToBlackBy(leds, NUM_LEDS, 15);
  byte t1 = millis() / 10;
  byte t2 = sin8(t1)/2;
  for (uint16_t i = 0; i < 13; i++) {
    byte x = sin8(t1 + i * 20)*LED_COLS/255; 
    byte y = sin8(t2 + i * 20)*LED_ROWS/255;   
    x= x>=LED_COLS? (LED_COLS-1):x;
    y= y>=LED_ROWS? (LED_ROWS-1):y;
    leds[XY(x, y)] = CHSV(i * 255 / 13, 255, 255);
  }
  blur2d(leds, LED_COLS, LED_ROWS,16);
      FastLED.show();

}
 
uint16_t XY( uint8_t x, uint8_t y)
{
  uint16_t i;
  if( kMatrixSerpentineLayout == false) {
    i = (y * kMatrixWidth) + x;
  }
  if( kMatrixSerpentineLayout == true) {
    if( y & 0x01) {
      // Odd rows run backwards
      uint8_t reverseX = (kMatrixWidth - 1) - x;
      i = (y * kMatrixWidth) + reverseX;
    } else {
      // Even rows run forwards
      i = (y * kMatrixWidth) + x;
    }
  }
  return i;
}