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 <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
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();
36 }
37
38 Str fxName() const override { return "NoisePalette"; }
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) {
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;
65 bool colorLoop = 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
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
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[NUM_LEDS]
Definition Apa102.ino:11
central include file for FastLED, defines the CFastLED class/object
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
UINumberField palette("Palette", 0, 0, 2)
void mapNoiseToLEDsUsingPalette()
RGB color palette with 16 discrete values.
XYMap mXyMap
Definition fx2d.h:29
uint16_t xyMap(uint16_t x, uint16_t y) const
Definition fx2d.h:20
Fx2d(const XYMap &xyMap)
Definition fx2d.h:19
_DrawContext DrawContext
Definition fx.h:21
CRGBPalette16 currentPalette
void SetupBlackAndWhiteStripedPalette()
uint8_t changeToRandomPalette()
bool hasFixedFrameRate(float *fps) const override
void setScale(uint16_t scale)
uint16_t XY(uint8_t x, uint8_t y) const
uint8_t getPalettePresetCount() const
fl::scoped_array< uint8_t > noise
Str fxName() const override
void SetupPurpleAndGreenPalette()
uint8_t getPalettePreset() const
void setSpeed(uint16_t speed)
void SetupRandomPalette()
NoisePalette(XYMap xyMap, float fps=60.f)
void setPalette(const CRGBPalette16 &palette, uint16_t speed, uint16_t scale, bool colorLoop)
void setPalettePreset(int paletteIndex)
void draw(DrawContext context) override
Definition str.h:368
#define FASTLED_SMART_PTR(type)
Definition ptr.h:17
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:44
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
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:635
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:499
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54