6#define FASTLED_INTERNAL
19NoisePalette::NoisePalette(XYMap xyMap,
float fps)
20 : Fx2d(xyMap), speed(0), scale(0), colorLoop(1), mFps(fps) {
22 static_assert(
sizeof(currentPalette) ==
sizeof(
CRGBPalette16),
23 "Palette size mismatch");
25 width = xyMap.getWidth();
26 height = xyMap.getHeight();
36 noise = scoped_ptr<uint8_t>(
new uint8_t[width * height]);
39void NoisePalette::setPalettePreset(
int paletteIndex) {
40 currentPaletteIndex = paletteIndex % 12;
41 switch (currentPaletteIndex) {
49 SetupPurpleAndGreenPalette();
55 SetupBlackAndWhiteStripedPalette();
94 speed = 20 + (currentPaletteIndex - 8) * 5;
95 scale = 20 + (currentPaletteIndex - 8) * 5;
109void NoisePalette::mapNoiseToLEDsUsingPalette(
CRGB *leds) {
110 static uint8_t ihue = 0;
112 for (uint16_t i = 0; i < width; i++) {
113 for (uint16_t j = 0; j < height; j++) {
118 uint8_t index = noise.get()[i * height + j];
119 uint8_t bri = noise.get()[j * width + i];
135 leds[XY(i, j)] = color;
142void NoisePalette::fillnoise8() {
147 uint8_t dataSmoothing = 0;
149 dataSmoothing = 200 - (speed * 4);
152 for (uint16_t i = 0; i < width; i++) {
153 int ioffset = scale * i;
154 for (uint16_t j = 0; j < height; j++) {
155 int joffset = scale * j;
157 uint8_t data =
inoise8(mX + ioffset, mY + joffset, mZ);
163 data =
qsub8(data, 16);
167 uint8_t olddata = noise.get()[i * height + j];
168 uint8_t newdata =
scale8(olddata, dataSmoothing) +
169 scale8(data, 256 - dataSmoothing);
173 noise.get()[i * height + j] = data;
184uint8_t NoisePalette::changeToRandomPalette() {
186 uint8_t new_idx =
random8() % 12;
187 if (new_idx == currentPaletteIndex) {
190 currentPaletteIndex = new_idx;
191 setPalettePreset(currentPaletteIndex);
192 return currentPaletteIndex;
central include file for FastLED, defines the CFastLED class/object
RGB color palette with 16 discrete values.
LIB8STATIC uint8_t dim8_raw(uint8_t x)
Adjust a scaling value for dimming.
LIB8STATIC_ALWAYS_INLINE uint8_t qadd8(uint8_t i, uint8_t j)
Add one byte to another, saturating at 0xFF.
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
uint8_t inoise8(uint16_t x, uint16_t y, uint16_t z)
8-Bit, fixed point implementation of Perlin's noise.
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
Get a color from a palette.
const TProgmemRGBPalette16 RainbowStripeColors_p
HSV Rainbow colors with alternatating stripes of black.
const TProgmemRGBPalette16 OceanColors_p
Ocean colors, blues and whites.
const TProgmemRGBPalette16 CloudColors_p
Cloudy color palette.
const TProgmemRGBPalette16 ForestColors_p
Forest colors, greens.
const TProgmemRGBPalette16 LavaColors_p
Lava color palette.
const TProgmemRGBPalette16 PartyColors_p
HSV color ramp: blue, purple, pink, red, orange, yellow (and back).
const TProgmemRGBPalette16 RainbowColors_p
HSV Rainbow.
LIB8STATIC uint16_t random16()
Generate a 16-bit random number.
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Implements a simple red square effect for 2D LED grids.
Functions to generate and fill arrays with noise.
Demonstrates how to mix noise generation with color palettes on a 2D LED matrix.
Fast, efficient random number generators specifically designed for high-performance LED programming.
Representation of an RGB pixel (Red, Green, Blue)