Colour transition
BlitzMax Forums/BlitzMax Programming/Colour transition
| ||
Does anyone have a good algorithm for smoothly changing one colour into another? |
| ||
I've used this to generate gradients: buttonwidth:int=200 buttonheight:int=100 ' Start and End color in HEX format RGBIn=$8b9eb1 RGBOut=$768796 bgr:Float=(RGBin & $FF0000) Shr 16 bgg:Float=(RGBin & $00FF00) Shr 8 bgb:Float=(RGBin & $0000FF) egr:Float=(RGBout & $FF0000) Shr 16 egg:Float=(RGBout & $00FF00) Shr 8 egb:Float=(RGBout & $0000FF) For t:Float = 0 To ButtonWidth newMod:Float=((1.0/ButtonWidth)*t) oldMod:Float=1-((1.0/ButtonWidth)*t) SetColor (bgr*oldmod)+(egr*newmod),(bgg*oldmod)+(egg*newmod),(bgb*oldmod)+(egb*newmod) DrawLine t,0,t,ButtonHeight*2 Next although depending on what you need it for (size, amount, how frequently?) and whether you use DX or OpenGL, there are low-level commands that draw quads with gradients applied to them which would be more efficient. |
| ||
Thanks Marc, that's great. :) |
| ||
I create gradients by creating a pixmap 1x2 pixels for example, one pixel for each color. Then I convert it into a TImage and use DrawImageRect(). It's the fastest way I've found so far :P |
| ||
I create gradients by creating a pixmap 1x2 pixels for example, one pixel for each color. If you want to get down and dirty, you could set the vertex colors and get a much faster gradient.Then I convert it into a TImage and use DrawImageRect(). This is specific to OpenGL, but it shouldn't be hard to make one for DirectX as well (but the implementation would be nasty without some modifications to brl.d3d7max2d): Then you could throw in my modifications of brl.glmax2d and make the gradients rotate and scale (given access to transform vars). |
| ||
Yeah, Vertex colors are fast. But they get screwed up by SetColor and other stuff later on. |