资料库: IncColors

 

IncColors:

该类包含与颜色工作的函数。它具有色彩转换等实用函数。

作者: Dmitry Fedoseev

 

这套色彩处理功能非常棒!谢谢您的帮助。

但是,我还缺少将位于给定区间内的数字转换为颜色的功能(在您的函数帮助下,颜色可以随意转换),这让我很不满意。

我使用了这样一种原始结构:

//+------------------------------------------------------------------+
//|JQS RainbowColour v1.0.0|
//|Copyright © 2010, JQS aka Joo.|
//|                                 http://www.mql4.com/ru/users/joo |
//|https://www.mql5.com/zh/users/joo|
//+------------------------------------------------------------------+
color RainbowColor(double BrushIn,double min,double max)
{
        string R,G,B;
        int temp;
        double Brush=ScaleColor(BrushIn,min,max,0.0,100.0);
        //如果小于下限
        if (Brush<0.0)
        {
                R="255";
                G="0";
                B="0";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //如果大于上限
        if (Brush>100.0)
        {
                R="255";
                G="0";
                B="255";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //从红色到黄色 255.0.0 -> 255.255.255.0
        if (Brush>=0.0 && Brush<20.0)
        {
                R="255";
                temp=(int)MathRound(ScaleColor(Brush,0.0,20.0,0.0,255.0));
                G=(string)temp;
                B="0";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //--------------------------------------------
        //从黄色到绿色 255.255.0 -> 0.255.0
        if (Brush>=20.0 && Brush<40.0)
        {
                temp=(int)(255.0-MathRound(ScaleColor(Brush-20.0,0.0,20.0,0.0,255.0)));
                R=(string)temp;
                G="255";
                B="0";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //--------------------------------------------
        //绿色到蓝色 0.255.0 -> 0.255.255.255
        if (Brush>=40.0 && Brush<60.0)
        {
                R="0";
                G="255";
                temp=(int)(MathRound(ScaleColor(Brush-40.0,0.0,20.0,0.0,255.0)));
                B=(string)temp;
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //--------------------------------------------
        //从青色到蓝色 0.255.255 -> 0.0.255
        if (Brush>=60.0 && Brush<80.0)
        {
                R="0";
                temp=(int)(255.0-MathRound(ScaleColor(Brush-60.0,0.0,20.0,0.0,255.0)));
                G=(string)temp;
                B="255";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        //--------------------------------------------
        //从蓝色到紫色 0.0.255 -> 255.0.255
        if (Brush>=80.0 && Brush<=100.0)
        {
                temp=(int)(MathRound(ScaleColor(Brush-80.0,0.0,20.0,0.0,255.0)));
                R=(string)temp;
                G="0";
                B="255";
                return(StringToColor("C'"+R+","+G+","+B+"'"));
        }
        return(StringToColor("C'"+(string)255+","+(string)255+","+(string)255+"'"));
}
//+------------------------------------------------------------------+

double ScaleColor(double In,double InMIN,double InMAX,double OutMIN,double OutMAX)
{
        double Out=((In-InMIN)*(OutMAX-OutMIN)/(InMAX-InMIN))+OutMIN;
        return(Out);
}
//+------------------------------------------------------------------+

该函数根据彩虹色标返回颜色。

你能把这个函数添加到函数库中吗?- 并在速度方面加以改进。

 
joo:

这套色彩处理功能非常棒!谢谢您的帮助。

但是,我还缺少将位于给定区间内的数字转换为颜色的功能(在您的函数帮助下,颜色可以随意转换),这让我很不满意。

我使用了这样一种原始结构:

该函数根据彩虹色标返回颜色。

你能把这个函数添加到函数库中吗?- 并在速度方面加以改进。

我会在闲暇时看一看,搞清楚这是一个什么样的函数,如果有必要,就把它加进去。但总的来说,HSL 和 HSL 之间是有转换的。H 分量是色调(色号),从 0 到 1 代表整个彩虹。