コード例 #1
0
ファイル: ColorLinear.cs プロジェクト: wwkkww1983/TestTool
        public Color GetColor(double pos)
        {
            int index = getIndex(pos);

            if (index < _colors.Count)
            {
                ColorPos right = _colors[index];
                if (index == 0 || pos == right.Pos)
                {
                    return(right.Color);
                }
                else
                {
                    ColorPos left       = _colors[index - 1];
                    double   rightRatio = (pos - left.Pos) / (right.Pos - left.Pos);
                    double   leftRatio  = 1 - rightRatio;
                    byte     r          = (byte)(leftRatio * left.Color.R + rightRatio * right.Color.R);
                    byte     g          = (byte)(leftRatio * left.Color.G + rightRatio * right.Color.G);
                    byte     b          = (byte)(leftRatio * left.Color.B + rightRatio * right.Color.B);
                    byte     a          = (byte)(leftRatio * left.Color.A + rightRatio * right.Color.A);
                    return(Color.FromArgb(a, r, g, b));
                }
            }
            else
            {
                return(Colors.Transparent);
            }
        }
コード例 #2
0
ファイル: ColorLinear.cs プロジェクト: wwkkww1983/TestTool
        public void AddColor(double pos, Color color)
        {
            ColorPos cp = new ColorPos()
            {
                Pos = pos, Color = color
            };
            int index = getIndex(pos);

            _colors.Insert(index, cp);
        }