FastLED 3.9.15
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 "fl/ptr.h"
11#include "fl/xymap.h"
12#include "fx/fx2d.h"
13#include "fx/time.h"
14#include "lib8tion/random8.h"
15#include "noise.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
24 // otherwise.
25 NoisePalette(XYMap xyMap, float fps = 60.f);
26
27 bool hasFixedFrameRate(float *fps) const override {
28 *fps = mFps;
29 return true;
30 }
31
32 // No need for a destructor, scoped_ptr will handle memory deallocation
33
34 void draw(DrawContext context) override {
35 fillnoise8();
37 }
38
39 Str fxName() const override { return "NoisePalette"; }
41
42 uint8_t changeToRandomPalette();
43
44 // There are 12 palette indexes but they don't have names. Use this to set
45 // which one you want.
46 uint8_t getPalettePresetCount() const { return 12; }
47 uint8_t getPalettePreset() const { return currentPaletteIndex; }
48 void setPalettePreset(int paletteIndex);
49 void setPalette(const CRGBPalette16 &palette, uint16_t speed,
50 uint16_t scale, bool colorLoop) {
52 this->speed = speed;
53 this->scale = scale;
54 this->colorLoop = colorLoop;
55 }
56 void setSpeed(uint16_t speed) { this->speed = speed; }
57 void setScale(uint16_t scale) { this->scale = scale; }
58
59 private:
60 uint16_t mX, mY, mZ;
61 uint16_t width, height;
62 uint16_t speed = 0;
63 uint16_t scale = 0;
65 CRGBPalette16 currentPalette;
66 bool colorLoop = 0;
68 float mFps = 60.f;
69
70 void fillnoise8();
71
72 uint16_t XY(uint8_t x, uint8_t y) const { return mXyMap.mapToIndex(x, y); }
73
75 CRGBPalette16 newPalette;
76 do {
77 newPalette = CRGBPalette16(
78 CHSV(random8(), 255, 32), CHSV(random8(), 255, 255),
79 CHSV(random8(), 128, 255), CHSV(random8(), 255, 255));
80 } while (newPalette == currentPalette);
81 currentPalette = newPalette;
82 }
83
91
93 CRGB purple = CHSV(HUE_PURPLE, 255, 255);
94 CRGB green = CHSV(HUE_GREEN, 255, 255);
95 CRGB black = CRGB::Black;
96
97 currentPalette = CRGBPalette16(
98 green, green, black, black, purple, purple, black, black, green,
99 green, black, black, purple, purple, black, black);
100 }
101};
102
103} // namespace fl
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
int y
Definition Audio.ino:72
int x
Definition Audio.ino:71
central include file for FastLED, defines the CFastLED class/object
UINumberField palette("Palette", 0, 0, 2)
void mapNoiseToLEDsUsingPalette()
XYMap mXyMap
Definition fx2d.h:31
uint16_t xyMap(uint16_t x, uint16_t y) const
Definition fx2d.h:21
Fx2d(const XYMap &xyMap)
Definition fx2d.h:20
_DrawContext DrawContext
Definition fx.h:21
CRGBPalette16 currentPalette
fl::vector< uint8_t, fl::allocator_psram< uint8_t > > noise
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
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:389
void fill_solid(struct CRGB *targetArray, int numToFill, const struct CRGB &color)
Fill a range of LEDs with a solid color.
Definition fill.cpp:9
@ 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:46
HeapVector< T, Allocator > vector
Definition vector.h:1074
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Functions to generate and fill arrays with noise.
#define FASTLED_SMART_PTR(type)
Definition ptr.h:31
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:640
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:504
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55