This is how to extract RGB values from a Color Int value

 
Hello,


While making the Heat Map Multicolor indicator I needed some colors functions. I used the two functions rgb2int() and colorgradient() published on http://www.thetradingtheory.com/colors-in-mql4/ (thanks to zenhop for sharing). These two functions do what they say: the 1st one rgb2int() returns an Integer from 3 RGB inputs, and colorgradient() helps drawing a gradient of colors from two sets of RGB values.

In order to give the user the choice of colors I had to convert the value of extern color Hot into RGB values, so I created the following functions, I hope you find them usefull.



/*
//--these three functions are used to extract the RGB values from the int clr
*/
int GetBlue(int clr)
{
int blue = MathFloor(clr / 65536);
return (blue);
}

int GetGreen(int clr)
{
int blue = MathFloor(clr / 65536);
int green = MathFloor((clr-(blue*65536)) / 256);
return (green);
}

int GetRed(int clr)
{
int blue = MathFloor(clr / 65536);
int green = MathFloor((clr-(blue*65536)) / 256);
int red = clr -(blue*65536) - (green*256);
return (red);
}


Regards

MT-Coder

 
am I missing something? why the complexity? why not use use & ? like 0x00FF000 or 0x0000FF, etc. and shift it