FastLED 3.10.8
Loading...
Searching...
No Matches
pacifica.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/noexcept.h"
4
5#include "fl/fx/fx1d.h"
6
7namespace fl {
8
12
14
15class Pacifica : public Fx1d {
16 public:
17 Pacifica(u16 num_leds) FL_NO_EXCEPT : Fx1d(num_leds) {}
18
19 void draw(DrawContext context) FL_NO_EXCEPT override;
20 fl::string fxName() const FL_NO_EXCEPT override { return "Pacifica"; }
21
22 private:
23 u16 sCIStart1 = 0, sCIStart2 = 0, sCIStart3 = 0, sCIStart4 = 0;
24 fl::u32 sLastms = 0;
25
26 CRGBPalette16 pacifica_palette_1 = {0x000507, 0x000409, 0x00030B, 0x00030D,
27 0x000210, 0x000212, 0x000114, 0x000117,
28 0x000019, 0x00001C, 0x000026, 0x000031,
29 0x00003B, 0x000046, 0x14554B, 0x28AA50};
30 CRGBPalette16 pacifica_palette_2 = {0x000507, 0x000409, 0x00030B, 0x00030D,
31 0x000210, 0x000212, 0x000114, 0x000117,
32 0x000019, 0x00001C, 0x000026, 0x000031,
33 0x00003B, 0x000046, 0x0C5F52, 0x19BE5F};
34 CRGBPalette16 pacifica_palette_3 = {0x000208, 0x00030E, 0x000514, 0x00061A,
35 0x000820, 0x000927, 0x000B2D, 0x000C33,
36 0x000E39, 0x001040, 0x001450, 0x001860,
37 0x001C70, 0x002080, 0x1040BF, 0x2060FF};
38
39 void pacifica_one_layer(fl::span<CRGB> leds, CRGBPalette16 &p, u16 cistart,
40 u16 wavescale, u8 bri, u16 ioff) FL_NO_EXCEPT;
43};
44
46 fl::span<CRGB> leds = ctx.leds;
47 fl::u32 now = ctx.now;
48 if (leds.empty() || mNumLeds == 0) {
49 return;
50 }
51
52 // Update the hue each time through the loop
53 fl::u32 ms = now;
54 fl::u32 deltams = ms - sLastms;
55 sLastms = ms;
56 u16 speedfactor1 = beatsin16(3, 179, 269);
57 u16 speedfactor2 = beatsin16(4, 179, 269);
58 fl::u32 deltams1 = (deltams * speedfactor1) / 256;
59 fl::u32 deltams2 = (deltams * speedfactor2) / 256;
60 fl::u32 deltams21 = (deltams1 + deltams2) / 2;
61 sCIStart1 += (deltams1 * beatsin88(1011, 10, 13));
62 sCIStart2 -= (deltams21 * beatsin88(777, 8, 11));
63 sCIStart3 -= (deltams1 * beatsin88(501, 5, 7));
64 sCIStart4 -= (deltams2 * beatsin88(257, 4, 6));
65
66 // Clear out the LED array to a dim background blue-green
67 fill_solid(leds, CRGB(2, 6, 10));
68
69 // Render each of four layers, with different scales and speeds, that vary
70 // over time
72 beatsin16(3, 11 * 256, 14 * 256), beatsin8(10, 70, 130),
73 0 - beat16(301));
75 beatsin16(4, 6 * 256, 9 * 256), beatsin8(17, 40, 80),
76 beat16(401));
78 beatsin8(9, 10, 38), 0 - beat16(503));
80 beatsin8(8, 10, 28), beat16(601));
81
82 // Add brighter 'whitecaps' where the waves lines up more
84
85 // Deepen the blues and greens a bit
87}
88
89// Add one layer of waves into the led array
91 u16 cistart, u16 wavescale,
92 u8 bri, u16 ioff) FL_NO_EXCEPT {
93 u16 ci = cistart;
94 u16 waveangle = ioff;
95 u16 wavescale_half = (wavescale / 2) + 20;
96 for (u16 i = 0; i < mNumLeds; i++) {
97 waveangle += 250;
98 u16 s16 = sin16(waveangle) + 32768;
99 u16 cs = scale16(s16, wavescale_half) + wavescale_half;
100 ci += cs;
101 u16 sindex16 = sin16(ci) + 32768;
102 u8 sindex8 = scale16(sindex16, 240);
103 CRGB c = ColorFromPalette(p, sindex8, bri, LINEARBLEND);
104 leds[i] += c;
105 }
106}
107
108// Add extra 'white' to areas where the four layers of light have lined up
109// brightly
111 u8 basethreshold = beatsin8(9, 55, 65);
112 u8 wave = beat8(7);
113
114 for (u16 i = 0; i < mNumLeds; i++) {
115 u8 threshold = scale8(sin8(wave), 20) + basethreshold;
116 wave += 7;
117 u8 l = leds[i].getAverageLight();
118 if (l > threshold) {
119 u8 overage = l - threshold;
120 u8 overage2 = qadd8(overage, overage);
121 leds[i] += CRGB(overage, overage2, qadd8(overage2, overage2));
122 }
123 }
124}
125
126// Deepen the blues and greens
128 for (u16 i = 0; i < mNumLeds; i++) {
129 leds[i].blue = scale8(leds[i].blue, 145);
130 leds[i].green = scale8(leds[i].green, 200);
131 leds[i] |= CRGB(2, 5, 7);
132 }
133}
134
135} // namespace fl
CRGB leds[1]
void pacifica_deepen_colors()
Definition Pacifica.ino:162
void pacifica_add_whitecaps()
Definition Pacifica.ino:144
void pacifica_one_layer(fl::CRGBPalette16 &p, uint16_t cistart, uint16_t wavescale, uint8_t bri, uint16_t ioff)
Definition Pacifica.ino:126
Fx1d(u16 numLeds) FL_NO_EXCEPT
Definition fx1d.h:13
u16 mNumLeds
Definition fx.h:53
void draw(DrawContext context) FL_NO_EXCEPT override
Definition pacifica.h:45
void pacifica_one_layer(fl::span< CRGB > leds, CRGBPalette16 &p, u16 cistart, u16 wavescale, u8 bri, u16 ioff) FL_NO_EXCEPT
Definition pacifica.h:90
u16 sCIStart4
Definition pacifica.h:23
void pacifica_deepen_colors(fl::span< CRGB > leds) FL_NO_EXCEPT
Definition pacifica.h:127
CRGBPalette16 pacifica_palette_1
Definition pacifica.h:26
fl::u32 sLastms
Definition pacifica.h:24
u16 sCIStart3
Definition pacifica.h:23
CRGBPalette16 pacifica_palette_3
Definition pacifica.h:34
fl::string fxName() const FL_NO_EXCEPT override
Definition pacifica.h:20
u16 sCIStart2
Definition pacifica.h:23
Pacifica(u16 num_leds) FL_NO_EXCEPT
Definition pacifica.h:17
CRGBPalette16 pacifica_palette_2
Definition pacifica.h:30
u16 sCIStart1
Definition pacifica.h:23
void pacifica_add_whitecaps(fl::span< CRGB > leds) FL_NO_EXCEPT
Definition pacifica.h:110
LIB8STATIC u8 beat8(accum88 beats_per_minute, u32 timebase=0) FL_NO_EXCEPT
Generates an 8-bit "sawtooth" wave at a given BPM.
Definition beat.h:51
LIB8STATIC u16 beatsin88(accum88 beats_per_minute_88, u16 lowest=0, u16 highest=65535, u32 timebase=0, u16 phase_offset=0) FL_NO_EXCEPT
Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
Definition beat.h:63
LIB8STATIC u16 beatsin16(accum88 beats_per_minute, u16 lowest=0, u16 highest=65535, u32 timebase=0, u16 phase_offset=0) FL_NO_EXCEPT
Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
Definition beat.h:84
LIB8STATIC u8 beatsin8(accum88 beats_per_minute, u8 lowest=0, u8 highest=255, u32 timebase=0, u8 phase_offset=0) FL_NO_EXCEPT
Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
Definition beat.h:105
LIB8STATIC u16 beat16(accum88 beats_per_minute, u32 timebase=0) FL_NO_EXCEPT
Generates a 16-bit "sawtooth" wave at a given BPM.
Definition beat.h:41
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
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:18
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType) FL_NO_EXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38