FastLED 3.10.8
Loading...
Searching...
No Matches
pride2015.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
13// Pride2015
14// Animated, ever-changing rainbows.
15// by Mark Kriegsman
16
18
19class Pride2015 : public Fx1d {
20 public:
21 Pride2015(u16 num_leds) FL_NO_EXCEPT : Fx1d(num_leds) {}
22
23 void draw(Fx::DrawContext context) FL_NO_EXCEPT override;
24 fl::string fxName() const FL_NO_EXCEPT override { return "Pride2015"; }
25
26 private:
27 u16 mPseudotime = 0;
28 u16 mLastMillis = 0;
29 u16 mHue16 = 0;
30};
31
32// This function draws rainbows with an ever-changing,
33// widely-varying set of parameters.
35 if (ctx.leds.empty() || mNumLeds == 0) {
36 return;
37 }
38
39 u8 sat8 = beatsin88(87, 220, 250);
40 u8 brightdepth = beatsin88(341, 96, 224);
41 u16 brightnessthetainc16 = beatsin88(203, (25 * 256), (40 * 256));
42 u8 msmultiplier = beatsin88(147, 23, 60);
43
44 u16 hue16 = mHue16;
45 u16 hueinc16 = beatsin88(113, 1, 3000);
46
47 u16 ms = fl::millis();
48 u16 deltams = ms - mLastMillis;
49 mLastMillis = ms;
50 mPseudotime += deltams * msmultiplier;
51 mHue16 += deltams * beatsin88(400, 5, 9);
52 u16 brightnesstheta16 = mPseudotime;
53
54 // set master brightness control
55 for (u16 i = 0; i < mNumLeds; i++) {
56 hue16 += hueinc16;
57 u8 hue8 = hue16 / 256;
58
59 brightnesstheta16 += brightnessthetainc16;
60 u16 b16 = sin16(brightnesstheta16) + 32768;
61
62 u16 bri16 = (fl::u32)((fl::u32)b16 * (fl::u32)b16) / 65536;
63 u8 bri8 = (fl::u32)(((fl::u32)bri16) * brightdepth) / 65536;
64 bri8 += (255 - brightdepth);
65
66 CRGB newcolor = CHSV(hue8, sat8, bri8);
67
68 u16 pixelnumber = (mNumLeds - 1) - i;
69
70 nblend(ctx.leds[pixelnumber], newcolor, 64);
71 }
72}
73
74} // namespace fl
Fx1d(u16 numLeds) FL_NO_EXCEPT
Definition fx1d.h:13
u16 mNumLeds
Definition fx.h:53
::fl::DrawContext DrawContext
Definition fx.h:21
fl::string fxName() const FL_NO_EXCEPT override
Definition pride2015.h:24
Pride2015(u16 num_leds) FL_NO_EXCEPT
Definition pride2015.h:21
void draw(Fx::DrawContext context) FL_NO_EXCEPT override
Definition pride2015.h:34
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
fl::hsv8 CHSV
Definition chsv.h:11
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
CRGB & nblend(CRGB &existing, const CRGB &overlay, fract8 amountOfOverlay) FL_NO_EXCEPT
Base definition for an LED controller.
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38