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