Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smooth out hue transitions. #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/Kaleidoscope/LED-Wavepool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

namespace kaleidoscope {

#define INTERPOLATE // smoother, slower animation
#define INTERPOLATE // smoother, slower animation
#define MS_PER_FRAME 40 // 40 = 25 fps
#define FRAMES_PER_DROP 120 // max time between raindrops during idle animation
#undef CONSTANT_HUE

int8_t WavepoolEffect::surface[2][WP_WID*WP_HGT];
uint8_t WavepoolEffect::page = 0;
Expand Down Expand Up @@ -90,8 +91,10 @@ void WavepoolEffect::update(void) {
// rotate the colors over time
// (side note: it's weird that this is a 16-bit int instead of 8-bit,
// but that's what the library function wants)
static uint8_t current_hue = 0;
static uint16_t current_hue = starting_hue;
#ifndef CONSTANT_HUE
current_hue ++;
#endif

frames_since_event ++;

Expand Down Expand Up @@ -197,14 +200,18 @@ void WavepoolEffect::update(void) {
#endif

uint8_t intensity = abs(height) * 2;
uint8_t saturation = 0xff - intensity;
uint8_t value = (intensity >= 128) ? 255 : intensity << 1;

// color starts white but gets dimmer and more saturated as it fades,
// with hue wobbling according to height map
#ifdef CONSTANT_HUE
int16_t hue = current_hue;
#else
int16_t hue = (current_hue + height + (height>>1)) & 0xff;
#endif

cRGB color = hsvToRgb(hue,
0xff - intensity,
((uint16_t)intensity)*2);
cRGB color = hsvToRgb(hue, saturation, value);

::LEDControl.setCrgbAt(r, c, color);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Kaleidoscope/LED-Wavepool.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class WavepoolEffect : public LEDMode {

// ms before idle animation starts after last keypress
static uint16_t idle_timeout;
// initial hue at keyboard boot, or all the time if CONSTANT_HUE is
// defined.
const uint8_t starting_hue = 192;

protected:
void setup(void) final;
Expand Down