CHSV& nblend( CHSV& existing, const CHSV& overlay, fract8 amountOfOverlay, TGradientDirectionCode directionCode) { if( amountOfOverlay == 0) { return existing; } if( amountOfOverlay == 255) { existing = overlay; return existing; } fract8 amountOfKeep = 256 - amountOfOverlay; uint8_t huedelta8 = overlay.hue - existing.hue; if( directionCode == SHORTEST_HUES ) { directionCode = FORWARD_HUES; if( huedelta8 > 127) { directionCode = BACKWARD_HUES; } } if( directionCode == LONGEST_HUES ) { directionCode = FORWARD_HUES; if( huedelta8 < 128) { directionCode = BACKWARD_HUES; } } if( directionCode == FORWARD_HUES) { existing.hue = existing.hue + scale8( huedelta8, amountOfOverlay); } else /* directionCode == BACKWARD_HUES */ { huedelta8 = -huedelta8; existing.hue = existing.hue - scale8( huedelta8, amountOfOverlay); } existing.sat = scale8_LEAVING_R1_DIRTY( existing.sat, amountOfKeep) + scale8_LEAVING_R1_DIRTY( overlay.sat, amountOfOverlay); existing.val = scale8_LEAVING_R1_DIRTY( existing.val, amountOfKeep) + scale8_LEAVING_R1_DIRTY( overlay.val, amountOfOverlay); cleanup_R1(); return existing; }
static int8_t __attribute__((always_inline)) lerp7by8( int8_t a, int8_t b, fract8 frac) { // int8_t delta = b - a; // int16_t prod = (uint16_t)delta * (uint16_t)frac; // int8_t scaled = prod >> 8; // int8_t result = a + scaled; // return result; int8_t result; if( b > a) { uint8_t delta = b - a; uint8_t scaled = scale8( delta, frac); result = a + scaled; } else { uint8_t delta = a - b; uint8_t scaled = scale8( delta, frac); result = a - scaled; } return result; }
void fadeUsingColor( CRGB* leds, uint16_t numLeds, const CRGB& colormask) { uint8_t fr, fg, fb; fr = colormask.r; fg = colormask.g; fb = colormask.b; for( uint16_t i = 0; i < numLeds; i++) { leds[i].r = scale8_LEAVING_R1_DIRTY( leds[i].r, fr); leds[i].g = scale8_LEAVING_R1_DIRTY( leds[i].g, fg); leds[i].b = scale8 ( leds[i].b, fb); } }
// Fill the x/y array of 8-bit noise values using the inoise8 function. void fillnoise8() { // If we're runing at a low "speed", some 8-bit artifacts become visible // from frame-to-frame. In order to reduce this, we can do some fast data-smoothing. // The amount of data smoothing we're doing depends on "speed". uint8_t dataSmoothing = 0; if( speed < 50) { dataSmoothing = 200 - (speed * 4); } for(int i = 0; i < MAP_WIDTH/2 + 1; i++) { int ioffset = scale * i; for(int j = 0; j < MAP_WIDTH/2 + 1; j++) { int joffset = scale * j; uint8_t data = inoise8(x + joffset,y + ioffset,z); // The range of the inoise8 function is roughly 16-238. // These two operations expand those values out to roughly 0..255 // You can comment them out if you want the raw noise data. data = qsub8(data,16); data = qadd8(data,scale8(data,39)); if( dataSmoothing ) { uint8_t olddata = noise[i][j]; uint8_t newdata = scale8( olddata, dataSmoothing) + scale8( data, 256 - dataSmoothing); data = newdata; } noise[i][j] = data; } } z += speed; // apply slow drift to X and Y, just for visual variation. x += speed * xDrift / 8; y -= speed * yDrift / 16; }
void RandomWipe::animate(CRGB* now, const CRGB* last, const uint8_t n, const uint8_t f) { uint8_t k = scale8(f, n); now[k] = _trgb; }