I am attempting to control a 240 long line of RGB pixels (ws2812b) using an artnet to dmx controller and need to generate colour gradients down the length of the line of pixels.
I had the idea of using the C# built in graphics libraries to generate the colour gradients and then extract the individual pixel values and send these to the dmx controller.
Is it possible to extract individual interpolated values from a LinearGradientBrush or a LinearGradientBrush applied to a shape (line/rectangle etc)?
Here is a function that takes a list of stop colors and returns a list of evenly interpolated colors:
You could call it as:
240 and 740 colors. To get all distinct colors make sure they are not too many and not too close, as the maximum number of RGB hues between two colors is 256, so the second example may hit that limit..
What you could do is let the brush draw a line on a bitmap and extract the pixels from that, but I believe that would be unnecessarily expensive and complicated. What would be better is simply lerping between the colours you want.
This can be achieved by writing a lerp method like so:
and using this for the R G and B values of the colors you want to lerp between. For example:
I hope this helps.
~Luca