FastLED 3.10.6
Loading...
Searching...
No Matches
mood_palette.cpp
Go to the documentation of this file.
1// mood_palette.cpp - mood to colour family.
2#include "mood_palette.h"
3
4#include "ring_canvas.h"
5
6namespace mood_ring {
7
8namespace {
9
10// Hue centres on the FastLED rainbow wheel (0..255).
11constexpr float kCoolHue = 150.0f; // teal-blue
12constexpr float kWarmHue = 20.0f; // amber-orange
13
14constexpr float kMinSpread = 24.0f;
15constexpr float kMaxSpread = 96.0f;
16constexpr float kMinSat = 150.0f;
17constexpr float kMaxSat = 255.0f;
18
19} // namespace
20
21MoodPalette paletteFor(const RoomSense &s, float hueDrift) {
23 // Travel the short way round the wheel from cool to warm (through
24 // magenta/red), which is the emotionally right path: sad -> tense ->
25 // happy, not sad -> green -> happy.
26 const float w = clampf(s.warmth, 0.0f, 1.0f);
27 float hue = kCoolHue + (kWarmHue + 256.0f - kCoolHue) * w;
28 hue += hueDrift * 256.0f;
29 while (hue >= 256.0f)
30 hue -= 256.0f;
31 while (hue < 0.0f)
32 hue += 256.0f;
33 p.hueBase = static_cast<fl::u8>(hue);
34
35 const float a = clampf(s.arousal, 0.0f, 1.0f);
36 p.hueSpread =
37 static_cast<fl::u8>(kMinSpread + (kMaxSpread - kMinSpread) * a);
38 p.saturation = static_cast<fl::u8>(kMinSat + (kMaxSat - kMinSat) * a);
39 return p;
40}
41
42RGBf paletteColor(const MoodPalette &p, float t) {
43 // Hue is quantised to the 256-step wheel, but neighbouring hues differ
44 // by about one unit per channel at full value, so a slow drift reads as
45 // continuous. Everything after this point stays in float.
46 const float tt = clampf(t, 0.0f, 1.0f);
47 const fl::u8 hue = static_cast<fl::u8>(
48 p.hueBase + static_cast<fl::u8>(tt * static_cast<float>(p.hueSpread)));
49 return toRGBf(CRGB(CHSV(hue, p.saturation, 255)));
50}
51
52} // namespace mood_ring
uint8_t hue
Definition advanced.h:94
static uint32_t t
Definition Luminova.h:55
fl::hsv8 CHSV
Definition chsv.h:11
fl::CRGB CRGB
Definition crgb.h:25
unsigned char u8
Definition stdint.h:131
RGBf toRGBf(CRGB c)
MoodPalette paletteFor(const RoomSense &s, float hueDrift)
Derive the family for this frame. Cheap; call every frame.
float clampf(float v, float lo, float hi)
Definition ring_canvas.h:19
RGBf paletteColor(const MoodPalette &p, float t)
Colour at position t in [0, 1] along the family, at value v.
float arousal
0 calm .. 1 energetic
Definition room_sense.h:55
fl::u8 hueSpread
how far t=1 travels from t=0
float warmth
0 cool .. 1 warm, from valence
Definition room_sense.h:54
fl::u8 hueBase
centre of the family
Everything a visual is allowed to react to.
Definition room_sense.h:31
Linear-light float pixel, nominal range [0, 1], may exceed 1 before clip.
Definition ring_canvas.h:24