17FASTLED_NAMESPACE_BEGIN
24 :
FxGrid(xyMap), speed(0), scale(0), colorLoop(1) {
25 width = xyMap.getWidth();
26 height = xyMap.getHeight();
41 void lazyInit()
override {}
45 mapNoiseToLEDsUsingPalette(context.leds);
48 const char *fxName(
int which)
const override {
return "NoisePalette"; }
50 void mapNoiseToLEDsUsingPalette(
CRGB *leds);
52 uint8_t changeToRandomPalette();
56 uint8_t getPalettePresetCount()
const {
return 12; }
57 uint8_t getPalettePreset()
const {
return currentPaletteIndex; }
58 void setPalettePreset(
int paletteIndex);
60 uint16_t scale,
bool colorLoop) {
61 currentPalette = palette;
64 this->colorLoop = colorLoop;
66 void setSpeed(uint16_t speed) { this->speed = speed; }
67 void setScale(uint16_t scale) { this->scale = scale; }
71 uint16_t width, height;
77 int currentPaletteIndex = 0;
83 uint16_t XY(uint8_t x, uint8_t y)
const {
return mXyMap.mapToIndex(x, y); }
85 void SetupRandomPalette() {
91 }
while (newPalette == currentPalette);
92 currentPalette = newPalette;
95 void SetupBlackAndWhiteStripedPalette() {
103 void SetupPurpleAndGreenPalette() {
104 CRGB purple =
CHSV(HUE_PURPLE, 255, 255);
105 CRGB green =
CHSV(HUE_GREEN, 255, 255);
109 green, green, black, black, purple, purple, black, black, green,
110 green, black, black, purple, purple, black, black);
114inline void NoisePalette::setPalettePreset(
int paletteIndex) {
115 currentPaletteIndex = paletteIndex % 12;
116 switch (currentPaletteIndex) {
124 SetupPurpleAndGreenPalette();
130 SetupBlackAndWhiteStripedPalette();
168 SetupRandomPalette();
169 speed = 20 + (currentPaletteIndex - 8) * 5;
170 scale = 20 + (currentPaletteIndex - 8) * 5;
182inline void NoisePalette::mapNoiseToLEDsUsingPalette(
CRGB *leds) {
183 static uint8_t ihue = 0;
185 for (uint16_t i = 0; i < width; i++) {
186 for (uint16_t j = 0; j < height; j++) {
191 uint8_t index = noise.get()[i * height + j];
192 uint8_t bri = noise.get()[j * width + i];
208 leds[XY(i, j)] = color;
215inline void NoisePalette::fillnoise8() {
220 uint8_t dataSmoothing = 0;
222 dataSmoothing = 200 - (speed * 4);
225 for (uint16_t i = 0; i < width; i++) {
226 int ioffset = scale * i;
227 for (
int j = 0; j < height; j++) {
228 int joffset = scale * j;
230 uint8_t data =
inoise8(mX + ioffset, mY + joffset, mZ);
236 data =
qsub8(data, 16);
240 uint8_t olddata = noise.get()[i * height + j];
241 uint8_t newdata =
scale8(olddata, dataSmoothing) +
242 scale8(data, 256 - dataSmoothing);
246 noise.get()[i * height + j] = data;
257inline uint8_t NoisePalette::changeToRandomPalette() {
259 uint8_t new_idx =
random8() % 12;
260 if (new_idx == currentPaletteIndex) {
263 currentPaletteIndex = new_idx;
264 setPalettePreset(currentPaletteIndex);
265 return currentPaletteIndex;
central include file for FastLED, defines the CFastLED class/object
RGB color palette with 16 discrete values.
void draw(DrawContext context) override
void fill_solid(struct CRGB *targetArray, int numToFill, const struct CRGB &color)
Fill a range of LEDs with a solid color.
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 ...
Functions to generate and fill arrays with noise.
Fast, efficient random number generators specifically designed for high-performance LED programming.
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Representation of an RGB pixel (Red, Green, Blue)