当前位置: 首页>>代码示例>>C#>>正文


C# ColorGradient.Lerp方法代码示例

本文整理汇总了C#中ColorGradient.Lerp方法的典型用法代码示例。如果您正苦于以下问题:C# ColorGradient.Lerp方法的具体用法?C# ColorGradient.Lerp怎么用?C# ColorGradient.Lerp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ColorGradient的用法示例。


在下文中一共展示了ColorGradient.Lerp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compose

        public override void Compose()
        {
            if (this.IsDirty)
            {
                this.Fill(Color.White, Color.Black, 0, null);

                _positions = Width;
                ColorGradient gradient = new ColorGradient(Color.Red, Color.Yellow, Color.Green, Color.Turquoise, Color.Blue, Color.Purple, Color.Red);

                for (int x = 0; x < Width; x++)
                {
                    this[x, 0].GlyphIndex = 219;
                    this[x, 0].Foreground = gradient.Lerp((float)x / (float)(Width - 1));
                }

                this[_selectedPosition, 1].GlyphIndex = 30;
                this[_selectedPosition, 1].Foreground = Color.LightGray;//this[_selectedPosition, 0].Foreground;

                // Build an array of all the colors
                Color[] colors = new Color[Width];
                for (int x = 0; x < Width; x++)
                    colors[x] = this[x, 0].Foreground;

                List<int> colorIndexesFinished = new List<int>(Width);

                foreach (var stop in gradient.Stops)
                {
                    ColorMine.ColorSpaces.Rgb rgbColorStop = new ColorMine.ColorSpaces.Rgb() { R = stop.Color.R, G = stop.Color.G, B = stop.Color.B };
                    Tuple<Color, double, int>[] colorWeights = new Tuple<Color, double, int>[Width];

                    // Create a color weight for every cell compared to the color stop
                    for (int x = 0; x < Width; x++)
                    {
                        if (!colorIndexesFinished.Contains(x))
                        {
                            ColorMine.ColorSpaces.Rgb rgbColor = new ColorMine.ColorSpaces.Rgb() { R = colors[x].R, G = colors[x].G, B = colors[x].B };
                            ColorMine.ColorSpaces.Cmy cmyColor = rgbColor.To<ColorMine.ColorSpaces.Cmy>();

                            colorWeights[x] = new Tuple<Color, double, int>(colors[x], rgbColorStop.Compare(cmyColor, new ColorMine.ColorSpaces.Comparisons.Cie1976Comparison()), x);
                        }
                        else
                            colorWeights[x] = new Tuple<Color, double, int>(colors[x], 10000, x);
                    }

                    var foundColor = colorWeights.OrderBy(t => t.Item2).First();

                    this[foundColor.Item3, 0].Foreground = stop.Color;
                    colorIndexesFinished.Add(foundColor.Item3);
                }

                this.IsDirty = false;
            }
        }
开发者ID:Thraka,项目名称:SadConsoleEditor,代码行数:53,代码来源:ColorBar.cs


注:本文中的ColorGradient.Lerp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。