Eliminate floating-point logic

Thanks to @noseglasses for the guidance!

Signed-off-by: Bart Nagel <bart@tremby.net>
pull/778/head
Bart Nagel 5 years ago
parent b16cda106b
commit 9a78f8f887

@ -111,14 +111,18 @@ uint8_t hue_end = 0;
cRGB BlazingTrail::compute(uint8_t *step) { cRGB BlazingTrail::compute(uint8_t *step) {
cRGB color; cRGB color;
// Get a float from 0 to 1 for our position in the animation // Get the position in the animation, where 0 is start and 0xff is end
float pos = (0xff - *step) / (float) 0xff; uint8_t pos255 = 0xff - *step;
// Fade hue linearly from orange to red // Fade hue linearly from orange to red
uint8_t hue = hue_start + pos * (hue_end - hue_start); uint8_t hue = hue_start + (pos255 * (hue_end - hue_start) >> 8);
// Fade value from full following a -x^4+1 curve // Fade value from full following a 1-x^4 curve
uint8_t val = 0xff * (1 - pos * pos * pos * pos); uint8_t val =
0xff // Maximum brightness
- ((uint32_t) pos255 * pos255 * pos255 * pos255 // Animation position to 4th power
>> 24) // ...pulled down to 8-bit range (but this has a maximum of 0xfc rather than 0xff)
- pos255 / (0x100 / 4); // Correction to bring the end result into a full 0 to 0xff range
color = hsvToRgb(hue, 0xff, val); color = hsvToRgb(hue, 0xff, val);

Loading…
Cancel
Save