I'm trying to understand the colorutils fill_gradient_RGB function.  I think datatypes saccum87 is int16_t

I’m trying to understand the colorutils fill_gradient_RGB function.

I think datatypes saccum87 is int16_t (since the uint8_t are multiplied by 128) and accum88 is unit16_t? What is the purpose of introducing these datatypes?

What does this line do?
int16_t divisor = p2 ? p2 : 1;

=
Question behind this question is that I notice some clear steps in my full brightness/saturated hues. Which isn’t really strange, because I use an RYBWheel function over the HSVRaw function (see testRYBwheel): https://gist.github.com/kasperkamperman/c720acf399efbae7e7b1

I think I lose a bit too much resolution. I’m now thinking where it could be smart to solve this. Maybe in this RYB function (where I could keep using the 16bit fractions of the fill gradient function)?

Another option would be using 64 “samples” from the RYB,HSV function and using 4 steps RGB in between with NBLEND. (I tried the 16palette, however that is to much difference).

I probably can also solve it by interpolating between 2 led buffers, however that is rather expensive (because I need to do it on all my 128 leds). However it can give smooth results. Would it be beneficial to even do that in 16bit?

I work now with the Teensy (ARM) so I’m not that limited.

Any thoughts and suggestions are welcome.

I’m not an expert on C, but I think

int16_t divisor = p2 ? p2 : 1;

Is a division by 0 protection. That code is a ternary operator that says "if p2 is true, use p2. If p2 is false, use “1”. The only way p2 would be false is if it is 0.

For now I’ve implemented interpolation with 3 buffers. It doesn’t seem so expensive as I had imagined (500 us). Please don’t confuse nblend with blend, that costed me a half night of sleep.

Here a working example. A random hue is picked in every new frame. We blend in 255 steps towards that value (we can increase the stepsize of course).

You know, I should write that down somewhere in the docs, and my apologies for the confusion: the “n_____” naming convention here means that the function is destructive; it modifies it’s argument (or it’s ‘this’ object) in place.

The convention comes from Common Lisp, where a function like “string-downcase” would return a new copy of it’s argument, but in lower case, and the corresponding function “nstring-downcase” would actual modify the string you passed into it, altering it in place to be all lower case.

It’s probably not a useful convention if no one else knows about it though. Added to my documentation To-Do list.

Well, I have to blame myself mostly not understanding pointers well. Luckily you get more skilled making mistakes :slight_smile: Still the best way to learn.

An old man told me once: “Experience is the sum of all the mistakes you made yourself.”