c++ Fade between colors? (Arduino)

前端 未结 3 1977
醉酒成梦
醉酒成梦 2021-01-28 01:11

I currently have this thats fading between 2 set colours:

for(int i=0;i

        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-28 01:57

    Smooth transitions between colours is best done in a different colour space (IMHO).

    As an example, to transition from bright red to bright green, do you want to go via bright yellow (around the edge of the colour wheel) or via #808000 (murky yellow) - which is what a straight line interpolation would give you in the RGB domain.

    Having done this for my Moodlamp app, I used the HSL colour space. I specified a start colour and end colour, along with a number of steps for the transition to take. That enabled me to calculate how much to adjust H, S and L by at each point in the transition.

    Only at the point of using the colour did I convert back to RGB.

    You can see the javascript code here (please bear in mind it's the first Javascript I ever wrote, so if it seems non-idiomatic, that's probably why!):

    https://github.com/martinjthompson/MoodLamp/blob/master/app/assistants/lamp-assistant.js

提交回复
热议问题