FastLED 3.9.15
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
15namespace fl {
16
18
19class NoisePalette : public Fx2d {
20 public:
21 // Fps is used by the fx_engine to maintain a fixed frame rate, ignored
22 // otherwise.
23 NoisePalette(XYMap xyMap, float fps = 60.f);
24
25 bool hasFixedFrameRate(float *fps) const override {
26 *fps = mFps;
27 return true;
28 }
29
30 // No need for a destructor, scoped_ptr will handle memory deallocation
31
32 void draw(DrawContext context) override {
33 fillnoise8();
35 }
36
37 string fxName() const override { return "NoisePalette"; }
39
41
42 // There are 12 palette indexes but they don't have names. Use this to set
43 // which one you want.
44 u8 getPalettePresetCount() const { return 12; }
46 void setPalettePreset(int paletteIndex);
47 void setPalette(const CRGBPalette16 &palette, u16 speed,
48 u16 scale, bool colorLoop) {
50 this->speed = speed;
51 this->scale = scale;
52 this->colorLoop = colorLoop;
53 }
54 void setSpeed(u16 speed) { this->speed = speed; }
55 void setScale(u16 scale) { this->scale = scale; }
56
57 private:
58 u16 mX, mY, mZ;
60 u16 speed = 0;
61 u16 scale = 0;
63 CRGBPalette16 currentPalette;
64 bool colorLoop = 0;
66 float mFps = 60.f;
67
68 void fillnoise8();
69
70 u16 XY(u8 x, u8 y) const { return mXyMap.mapToIndex(x, y); }
71
73 CRGBPalette16 newPalette;
74 do {
75 newPalette = CRGBPalette16(
76 CHSV(random8(), 255, 32), CHSV(random8(), 255, 255),
77 CHSV(random8(), 128, 255), CHSV(random8(), 255, 255));
78 } while (newPalette == currentPalette);
79 currentPalette = newPalette;
80 }
81
89
91 CRGB purple = CHSV(HUE_PURPLE, 255, 255);
92 CRGB green = CHSV(HUE_GREEN, 255, 255);
93 CRGB black = CRGB::Black;
94
95 currentPalette = CRGBPalette16(
96 green, green, black, black, purple, purple, black, black, green,
97 green, black, black, purple, purple, black, black);
98 }
99};
100
101} // namespace fl
fl::CRGB leds[NUM_LEDS]
UINumberField palette("Palette", 0, 0, 2)
XYMap mXyMap
Definition fx2d.h:30
Fx2d(const XYMap &xyMap)
Definition fx2d.h:19
u16 xyMap(u16 x, u16 y) const
Definition fx2d.h:20
u8 getPalettePresetCount() const
void setScale(u16 scale)
CRGBPalette16 currentPalette
string fxName() const override
u8 getPalettePreset() const
void mapNoiseToLEDsUsingPalette(fl::span< CRGB > leds)
void SetupBlackAndWhiteStripedPalette()
bool hasFixedFrameRate(float *fps) const override
void SetupPurpleAndGreenPalette()
fl::vector_psram< u8 > noise
u16 XY(u8 x, u8 y) const
void setSpeed(u16 speed)
void SetupRandomPalette()
NoisePalette(XYMap xyMap, float fps=60.f)
void setPalettePreset(int paletteIndex)
void setPalette(const CRGBPalette16 &palette, u16 speed, u16 scale, bool colorLoop)
void draw(DrawContext context) override
Fast, efficient random number generators specifically designed for high-performance LED programming.
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color)
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:9
fl::hsv8 CHSV
Definition chsv.h:11
@ HUE_GREEN
Green (135°)
Definition hsv.h:101
@ HUE_PURPLE
Purple (270°)
Definition hsv.h:104
LIB8STATIC fl::u8 random8() FL_NOEXCEPT
Generate an 8-bit random number.
Definition random8.h:53
unsigned char u8
Definition stdint.h:131
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:535
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:646
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
fl::span< CRGB > leds