17NoisePalette::NoisePalette(XYMap xyMap,
float fps)
18 : Fx2d(xyMap), speed(0), scale(0), colorLoop(1), mFps(fps) {
20 static_assert(
sizeof(currentPalette) ==
sizeof(
CRGBPalette16),
21 "Palette size mismatch");
23 width = xyMap.getWidth();
24 height = xyMap.getHeight();
34 noise = scoped_ptr<uint8_t>(
new uint8_t[width * height]);
37void NoisePalette::setPalettePreset(
int paletteIndex) {
38 currentPaletteIndex = paletteIndex % 12;
39 switch (currentPaletteIndex) {
47 SetupPurpleAndGreenPalette();
53 SetupBlackAndWhiteStripedPalette();
92 speed = 20 + (currentPaletteIndex - 8) * 5;
93 scale = 20 + (currentPaletteIndex - 8) * 5;
105void NoisePalette::mapNoiseToLEDsUsingPalette(
CRGB *leds) {
106 static uint8_t ihue = 0;
108 for (uint16_t i = 0; i < width; i++) {
109 for (uint16_t j = 0; j < height; j++) {
114 uint8_t index = noise.get()[i * height + j];
115 uint8_t bri = noise.get()[j * width + i];
131 leds[XY(i, j)] = color;
138void NoisePalette::fillnoise8() {
143 uint8_t dataSmoothing = 0;
145 dataSmoothing = 200 - (speed * 4);
148 for (uint16_t i = 0; i < width; i++) {
149 int ioffset = scale * i;
150 for (uint16_t j = 0; j < height; j++) {
151 int joffset = scale * j;
153 uint8_t data =
inoise8(mX + ioffset, mY + joffset, mZ);
159 data =
qsub8(data, 16);
163 uint8_t olddata = noise.get()[i * height + j];
164 uint8_t newdata =
scale8(olddata, dataSmoothing) +
165 scale8(data, 256 - dataSmoothing);
169 noise.get()[i * height + j] = data;
180uint8_t NoisePalette::changeToRandomPalette() {
182 uint8_t new_idx =
random8() % 12;
183 if (new_idx == currentPaletteIndex) {
186 currentPaletteIndex = new_idx;
187 setPalettePreset(currentPaletteIndex);
188 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)