FastLED 3.10.8
Loading...
Searching...
No Matches
noisepalette.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "fl/stl/stdint.h"
8
9#include "fl/stl/shared_ptr.h" // For FASTLED_SHARED_PTR macros
10#include "fl/stl/shared_ptr.h" // For shared_ptr
11#include "fl/math/xymap.h"
12#include "fl/fx/fx2d.h"
13#include "fl/math/random8.h"
14#include "fl/stl/noexcept.h"
15
16namespace fl {
17
19
20class NoisePalette : public Fx2d {
21 public:
22 // Fps is used by the fx_engine to maintain a fixed frame rate, ignored
23 // otherwise.
24 NoisePalette(XYMap xyMap, float fps = 60.f) FL_NO_EXCEPT;
25
26 bool hasFixedFrameRate(float *fps) const FL_NO_EXCEPT 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) FL_NO_EXCEPT override {
34 fillnoise8();
35 mapNoiseToLEDsUsingPalette(context.leds);
36 }
37
38 string fxName() const FL_NO_EXCEPT override { return "NoisePalette"; }
40
42
43 // There are 12 palette indexes but they don't have names. Use this to set
44 // which one you want.
45 u8 getPalettePresetCount() const FL_NO_EXCEPT { return 12; }
47 void setPalettePreset(int paletteIndex) FL_NO_EXCEPT;
48 void setPalette(const CRGBPalette16 &palette, u16 speed,
49 u16 scale, bool colorLoop) FL_NO_EXCEPT {
51 this->speed = speed;
52 this->scale = scale;
53 this->colorLoop = colorLoop;
54 }
55 void setSpeed(u16 speed) FL_NO_EXCEPT { this->speed = speed; }
56 void setScale(u16 scale) FL_NO_EXCEPT { this->scale = scale; }
57
58 private:
59 u16 mX, mY, mZ;
61 u16 speed = 0;
62 u16 scale = 0;
64 CRGBPalette16 currentPalette;
65 bool colorLoop = 0;
67 float mFps = 60.f;
68
70
71 u16 XY(u8 x, u8 y) const FL_NO_EXCEPT { return mXyMap.mapToIndex(x, y); }
72
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
90
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
CRGB leds[1]
UINumberField palette("Palette", 0, 0, 2)
XYMap mXyMap
Definition fx2d.h:31
u16 xyMap(u16 x, u16 y) const FL_NO_EXCEPT
Definition fx2d.h:21
Fx2d(const XYMap &xyMap) FL_NO_EXCEPT
Definition fx2d.h:20
void setPalette(const CRGBPalette16 &palette, u16 speed, u16 scale, bool colorLoop) FL_NO_EXCEPT
void SetupPurpleAndGreenPalette() FL_NO_EXCEPT
CRGBPalette16 currentPalette
void setPalettePreset(int paletteIndex) FL_NO_EXCEPT
void setScale(u16 scale) FL_NO_EXCEPT
void mapNoiseToLEDsUsingPalette(fl::span< CRGB > leds) FL_NO_EXCEPT
void SetupRandomPalette() FL_NO_EXCEPT
string fxName() const FL_NO_EXCEPT override
u16 XY(u8 x, u8 y) const FL_NO_EXCEPT
u8 getPalettePreset() const FL_NO_EXCEPT
u8 getPalettePresetCount() const FL_NO_EXCEPT
bool hasFixedFrameRate(float *fps) const FL_NO_EXCEPT override
void fillnoise8() FL_NO_EXCEPT
fl::vector_psram< u8 > noise
void SetupBlackAndWhiteStripedPalette() FL_NO_EXCEPT
NoisePalette(XYMap xyMap, float fps=60.f) FL_NO_EXCEPT
void draw(DrawContext context) FL_NO_EXCEPT override
u8 changeToRandomPalette() FL_NO_EXCEPT
void setSpeed(u16 speed) FL_NO_EXCEPT
Fast, efficient random number generators specifically designed for high-performance LED programming.
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NO_EXCEPT
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:10
fl::hsv8 CHSV
Definition chsv.h:11
@ HUE_GREEN
Green (135°)
Definition hsv.h:127
@ HUE_PURPLE
Purple (270°)
Definition hsv.h:130
LIB8STATIC fl::u8 random8() FL_NO_EXCEPT
Generate an 8-bit random number.
Definition random8.h:53
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:653
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:517
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38