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