#include <FastLED.h>
#define HEIGHT 6
#define WIDTH 64
#define NUM_LEDS WIDTH * HEIGHT
#define MATRIX_TYPE 1
// LEDs pin
#define DATA_PIN 2
// LED brightness
#define BRIGHTNESS 255
// Define the array of leds
CRGB leds[NUM_LEDS];

CRGB FirePalColor(uint8_t temp, uint8_t col) {
  CRGB TEMP_COL;
  uint8_t* colIndex[3] {(col / 2) + (uint8_t*)&TEMP_COL,                      //1 channel RRGGBB
                        ((((col + 3) / 2)) % 3) + (uint8_t*)&TEMP_COL,        //2 channel GBBRRG
                        ((2 - col) % 3) + (uint8_t*)&TEMP_COL                 //3 channel BGRBGR
                       };
  uint8_t t192 = scale8_video( temp, 191);

  // calculate a value that ramps up from
  // zero to 255 in each 'third' of the scale.
  uint8_t heatramp = t192 & 0x3F; // 0..63
  heatramp <<= 2; // scale up to 0..252
  if ( t192 & 0x80) { //to white
    *colIndex[0] = 255;
    *colIndex[1] = 255;
    *colIndex[2] = heatramp;
  } else if ( t192 & 0x40 ) { //2 channels
    *colIndex[0] = 255;
    *colIndex[1] = heatramp;
    *colIndex[2] = 0;
  } else {//1 channel
    *colIndex[0] = heatramp;
    *colIndex[1] = 0;
    *colIndex[2] = 0;
  }
  return TEMP_COL;
}

void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  Serial.begin(9600);
}
uint16_t a;
void loop() {
  a += 8;
  for (uint8_t y = 0; y < HEIGHT; y++) {
    for (uint8_t x = 0; x < WIDTH; x++) {
      leds[XY(x, y)] = FirePalColor(constrain(inoise8(x * 32 - a, y * 128) - x * (255 / WIDTH), 0, 255), y);
    }
  }
  FastLED.show();
}

uint16_t XY (uint8_t x, uint8_t y) {
  return (y * WIDTH + x);
}