// source: https://editor.soulmatelights.com/gallery/238-dna

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

uint8_t mn = 255 / (NUM_COLS * 2);
uint8_t speeds =40;
uint8_t freq = 10;
//#define mn 255 / (NUM_COLS * 2)
//#define speeds 40 // speed of rotation 
//#define freq 10 //change this will made spiral big or small 

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, 30);
  
  for (int i = 0; i < NUM_ROWS; i++) {
    uint16_t ms = millis();
    leds[i * NUM_COLS + beatsin8(speeds, 0, NUM_COLS - 1, 0, i * freq)] += CHSV(ms / 30 + i * 255 / (NUM_ROWS - 1), 255, beatsin8(speeds, 30, BRIGHTNESS, 0, i * mn + 64));
    leds[i * NUM_COLS + beatsin8(speeds, 0, NUM_COLS - 1, 0, 128 + i * freq)] += CHSV(ms / 30 + ((i * 255 / (NUM_ROWS - 1)) + 128), 255, beatsin8(speeds, 30, BRIGHTNESS, 0, i * mn + 192));
  }
 blur2d(leds, NUM_COLS, NUM_ROWS, 20);
    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;
}