FastLED 3.9.7
Loading...
Searching...
No Matches
noisepalette.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <stdint.h>
8
9#include "FastLED.h"
10#include "fx/fx2d.h"
11#include "lib8tion/random8.h"
12#include "noise.h"
13#include "fl/ptr.h"
14#include "fl/xymap.h"
15#include "fx/time.h"
16
17namespace fl {
18
19FASTLED_SMART_PTR(NoisePalette);
20
21class NoisePalette : public Fx2d {
22 public:
23 // Fps is used by the fx_engine to maintain a fixed frame rate, ignored otherwise.
24 NoisePalette(XYMap xyMap, float fps = 60.f);
25
26 bool hasFixedFrameRate(float *fps) const override {
27 *fps = mFps;
28 return true;
29 }
30
31 // No need for a destructor, scoped_ptr will handle memory deallocation
32
33 void draw(DrawContext context) override {
34 fillnoise8();
35 mapNoiseToLEDsUsingPalette(context.leds);
36 }
37
38 Str fxName() const override { return "NoisePalette"; }
39 void mapNoiseToLEDsUsingPalette(CRGB *leds);
40
41 uint8_t changeToRandomPalette();
42
43 // There are 12 palette indexes but they don't have names. Use this to set
44 // which one you want.
45 uint8_t getPalettePresetCount() const { return 12; }
46 uint8_t getPalettePreset() const { return currentPaletteIndex; }
47 void setPalettePreset(int paletteIndex);
48 void setPalette(const CRGBPalette16 &palette, uint16_t speed,
49 uint16_t scale, bool colorLoop) {
50 currentPalette = palette;
51 this->speed = speed;
52 this->scale = scale;
53 this->colorLoop = colorLoop;
54 }
55 void setSpeed(uint16_t speed) { this->speed = speed; }
56 void setScale(uint16_t scale) { this->scale = scale; }
57
58 private:
59 uint16_t mX, mY, mZ;
60 uint16_t width, height;
61 uint16_t speed = 0;
62 uint16_t scale = 0;
64 CRGBPalette16 currentPalette;
65 bool colorLoop = 0;
66 int currentPaletteIndex = 0;
67 float mFps = 60.f;
68
69 void fillnoise8();
70
71 uint16_t XY(uint8_t x, uint8_t y) const { return mXyMap.mapToIndex(x, y); }
72
73 void SetupRandomPalette() {
74 CRGBPalette16 newPalette;
75 do {
76 newPalette = CRGBPalette16(
77 CHSV(random8(), 255, 32), CHSV(random8(), 255, 255),
78 CHSV(random8(), 128, 255), CHSV(random8(), 255, 255));
79 } while (newPalette == currentPalette);
80 currentPalette = newPalette;
81 }
82
83 void SetupBlackAndWhiteStripedPalette() {
84 fill_solid(currentPalette, 16, CRGB::Black);
85 currentPalette[0] = CRGB::White;
86 currentPalette[4] = CRGB::White;
87 currentPalette[8] = CRGB::White;
88 currentPalette[12] = CRGB::White;
89 }
90
91 void SetupPurpleAndGreenPalette() {
92 CRGB purple = CHSV(HUE_PURPLE, 255, 255);
93 CRGB green = CHSV(HUE_GREEN, 255, 255);
94 CRGB black = CRGB::Black;
95
96 currentPalette = CRGBPalette16(
97 green, green, black, black, purple, purple, black, black, green,
98 green, black, black, purple, purple, black, black);
99 }
100};
101
102} // namespace fl
central include file for FastLED, defines the CFastLED class/object
RGB color palette with 16 discrete values.
Definition colorutils.h:997
void draw(DrawContext context) override
Definition str.h:336
void fill_solid(struct CRGB *targetArray, int numToFill, const struct CRGB &color)
Fill a range of LEDs with a solid color.
@ HUE_PURPLE
Purple (270°)
Definition chsv.h:104
@ HUE_GREEN
Green (135°)
Definition chsv.h:101
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
Definition random8.h:40
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
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)).
Definition chsv.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54
@ White
Definition crgb.h:632
@ Black
Definition crgb.h:496