Move38 / Blinks-SDK

Development for Blinks starts here. This codebase includes everything you need to get up and running in the Arduino IDE with Blinks.

Home Page:http://forum.move38.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: lighten()

ReluctantPirate opened this issue · comments

Just had an idea for a new color function: lighten(). This would function similarly to the dim() function, except in the case of lighten it would transition from the color itself to pure white. For example:

lighten(RED, 0) would appear as just RED
lighten(RED, 255) would appear as pure white
lighten(RED, 127) would appear as desaturated red (essentially R-255 G-127 B-127)

This could help developers make white flashes (a common animation trick) with RGB-defined colors.

Does seem only fair to be symmetrical with dim(). Maybe the two functions should be renamed toWhite(c,b) and toBlack(c,b). Heck maybe be general with toColor(from,to,step)?

Note that these can all be added to any program now by just including them at the top or in an include file. They can also be added to the API with the only risk being breaking existing code that may have these names already used.

I think dim() is already really clear, and lighten() seems like a nice parallel.

That being said, the generic color changing would be awesome as a function. Maybe something like colorShift() or colorChange() or colorSlide().

That being said, the generic color changing would be awesome as a function

Note that there are multiple ways to interpolate between colors...

https://www.alanzucconi.com/2016/01/06/colour-interpolation/2/

I think you can implement any of them using the current makeColorRGB() and makeColorHSV() functions?

Ok, new lighten() included in current open PR.

Here is LightenTest.ino...

void setup() {
  // put your setup code here, to run once:

}


Color baseColors[] = { RED, GREEN , BLUE, ORANGE , OFF , YELLOW };

byte colorIndex=0;
byte brightness=0;

Timer nextStep;

const unsigned STEP_TIME_MS  = 1;

void loop() {

  if (nextStep.isExpired()) {

    if (brightness < MAX_BRIGHTNESS) {

      brightness++;

    } else {

      brightness = 0;

      colorIndex++;

      if (colorIndex == COUNT_OF( baseColors ) ) {
        colorIndex = 0;
      }

    }

    nextStep.set( STEP_TIME_MS );

  }

  setColor( lighten( baseColors[colorIndex] , brightness ) );
  

}