#include <FastLED.h>

#define LED_PIN     3
#define NUM_LEDS    64
#define BRIGHTNESS  255
#define FRAMES_PER_SECOND 60

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
  // Fill the LED array with colors based on cellular noise
  fillCellularNoise();

  // Show the LED array
  FastLED.show();

  // Delay to control the animation speed
  delay(1000 / FRAMES_PER_SECOND);
}

void fillCellularNoise() {
  // Define the properties of the cellular noise
  uint8_t density = 150;  // Adjust this value to control the density of cells
  uint8_t scale = 16;     // Adjust this value to control the size of cells
  uint8_t colorSpeed = 4; // Adjust this value to control the color animation speed

  // Iterate through each pixel in the LED array
  for (uint16_t i = 0; i < NUM_LEDS; i++) {
    // Calculate the cellular noise value for the current pixel
    uint8_t value = inoise8(i * scale, millis() / colorSpeed) % 255;

    // Map the noise value to the LED's color range
    leds[i] = ColorFromPalette(RainbowColors_p, value, 255, LINEARBLEND);

    // Apply density threshold to create cells
    if (value > density) {
      leds[i] = CRGB::Black;  // Set the cell color to black
    }
  }
}