Exemple #1
0
        private static void Main(string[] args)
        {
            var red    = new Color(ColorTypes.Red);
            var yellow = new Color(ColorTypes.Yellow);
            var blue   = new Color(ColorTypes.Blue);


            Assert("Orange", red.Add(yellow).ToString());
            Assert("Orange", yellow.Add(red).ToString());
            Assert("Red", red.Add(red).ToString());
            Assert("Green", yellow.Add(blue).ToString());
            Assert("Purple", blue.Add(red).ToString());
        }
Exemple #2
0
        public static void ChangeStatusBarColor(Color backgroundColor, Color?_foregroundColor = null, ElementTheme?theme = ElementTheme.Dark)
        {
            theme = theme ?? AppSettings.Instance.Theme;
            byte blackOrWhiteByte = theme == ElementTheme.Light ? (byte)0x00 : (byte)0xff;

            Color foregroundColor = _foregroundColor ?? Color.FromArgb(0xD0, blackOrWhiteByte, blackOrWhiteByte, blackOrWhiteByte);

            if (foregroundColor.A < 0xff)
            {
                foregroundColor   = backgroundColor.Add(foregroundColor);
                foregroundColor.A = 0xff;
            }

            Color backgroundHoverColor = backgroundColor.Add(Color.FromArgb(0x20, blackOrWhiteByte, blackOrWhiteByte, blackOrWhiteByte)); //10%
            Color foregroundHoverColor = foregroundColor;

            foregroundHoverColor.A = 0xff;

            Color backgroundPressedColor = backgroundHoverColor.Add(Color.FromArgb(0x20, blackOrWhiteByte, blackOrWhiteByte, blackOrWhiteByte)); //10%
            Color foregroundPressedColor = foregroundHoverColor;


            bool hasStatusBar = Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar");

            if (hasStatusBar)
            {
                StatusBar.GetForCurrentView().BackgroundOpacity = backgroundColor.A;
                StatusBar.GetForCurrentView().BackgroundColor   = backgroundColor;
                StatusBar.GetForCurrentView().ForegroundColor   = foregroundColor;
            }

#if WINDOWS_UWP
            var titleBar = ApplicationView.GetForCurrentView().TitleBar;
            //System.Diagnostics.Debug.WriteLine("StatuBar background={0}, foreground={1}", backgroundColor, foregroundColor);

            titleBar.ForegroundColor               = foregroundColor;
            titleBar.ButtonForegroundColor         = foregroundColor;
            titleBar.InactiveForegroundColor       = foregroundColor;
            titleBar.ButtonInactiveForegroundColor = foregroundColor;
            titleBar.ButtonHoverForegroundColor    = foregroundHoverColor;
            titleBar.ButtonPressedForegroundColor  = foregroundPressedColor;

            titleBar.BackgroundColor               = backgroundColor;
            titleBar.InactiveBackgroundColor       = backgroundColor;
            titleBar.ButtonBackgroundColor         = backgroundColor;
            titleBar.ButtonInactiveBackgroundColor = backgroundColor;
            titleBar.ButtonHoverBackgroundColor    = backgroundHoverColor;
            titleBar.ButtonPressedBackgroundColor  = backgroundPressedColor;
#endif
        }
Exemple #3
0
        public void Render(RenderComposer c)
        {
            var colorMultiplier = (byte)(_mouseDragging ? 100 : 50);

            c.RenderOutline(Rect, Color);
            if (_anchor == 5)
            {
                c.RenderSprite(Rect, Color.Add(Color, colorMultiplier).SetAlpha(colorMultiplier));
            }

            c.RenderCircle(Rect.Position.ToVec3(), 2, _anchor == 1 ? Color.Add(Color, colorMultiplier) : Color, true);
            c.RenderCircle(Rect.TopRight.ToVec3(), 2, _anchor == 2 ? Color.Add(Color, colorMultiplier) : Color, true);
            c.RenderCircle(Rect.BottomRight.ToVec3(), 2, _anchor == 3 ? Color.Add(Color, colorMultiplier) : Color, true);
            c.RenderCircle(Rect.BottomLeft.ToVec3(), 2, _anchor == 4 ? Color.Add(Color, colorMultiplier) : Color, true);
        }
Exemple #4
0
        /// <summary>
        /// Перевод значения в диапазоне в цвет
        /// </summary>
        /// <param name="weight">значение</param>
        /// <param name="minWeight">минимальное значение</param>
        /// <param name="avgWeight"></param>
        /// <param name="maxWeight">максимальное значение</param>
        /// <param name="minColor">цвет минимального значения</param>
        /// <param name="avgColor">цвет среднего значения</param>
        /// <param name="maxColor">цвет максимального значения</param>
        /// <returns></returns>
        private Color WeightToColor(
            int weight,
            int minWeight,
            int avgWeight,
            int maxWeight,
            Color minColor,
            Color avgColor,
            Color maxColor)
        {
            var midWeight = avgWeight; // возможно требуеся пересчитать через avg

            Color lColor, rColor;
            float delta;

            if (weight < midWeight)
            {
                lColor = minColor;
                rColor = avgColor;
                delta  = (float)weight / (midWeight - minWeight);
            }
            else
            {
                lColor = avgColor;
                rColor = maxColor;
                delta  = (float)weight / (maxWeight - midWeight);
            }

            var dClr = Color.Subtract(rColor, lColor);

            return(Color.Add(lColor, Color.FromScRgb(dClr.ScA, dClr.ScR * delta, dClr.ScG * delta,
                                                     dClr.ScB * delta)));
        }
        /// <summary>
        /// private constructor to force use of factory methods
        /// </summary>
        /// <param name="node">the good node</param>
        /// <param name="goodType">the good type</param>
        private Good(KeyValueNode node, GoodTypeEnum goodType) : base(node.Key)
        {
            GoodType = goodType;
            Cost     = node["cost"].Value.AsDecimal();
            var children = node.Children;


            if (children.ContainsKey("available_from_start"))
            {
                AvailableFromStart = node["available_from_start"].Value.AsBool();
            }

            if (children.ContainsKey("overseas_penalty"))
            {
                OverseasPenalty = node["overseas_penalty"].Value.AsBool();
            }

            if (children.ContainsKey("tradeable"))
            {
                Tradeable = node["tradeable"].Value.AsBool();
            }

            if (children.ContainsKey("money"))
            {
                Money = node["money"].Value.AsBool();
            }

            var colors = node["color"];

            foreach (var child in colors)
            {
                Color.Add(child.Key.AsInt());
            }
        }
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var exception = new Exception("Cannot resolve colour!");

            var combinedColor = new Color();

            foreach (var value in values)
            {
                if (value == null || string.IsNullOrEmpty(value.ToString()))
                {
                    throw exception;
                }

                var color = (Color)ColorConverter.ConvertFromString(value.ToString());

                combinedColor = Color.Add(combinedColor, color);
            }

            if (targetType == typeof(Color))
            {
                return(combinedColor);
            }

            if (targetType == typeof(Brush))
            {
                return(new SolidColorBrush(combinedColor));
            }

            throw exception;
        }
Exemple #7
0
        /// <summary>
        /// Linear color interpolation.
        /// </summary>
        public static Color Lerp(Color toColor, Color fromColor, float amount)
        {
            Color delta = toColor.Subtract(fromColor);

            delta = delta.Multiply(amount);
            return(fromColor.Add(delta));
        }
        public void ProcessImage(PictureHandler sourceImage, PictureHandler targetImage)
        {
            var   source = sourceImage.Clone() as PictureHandler;
            Color eCol, bOw, c;
            byte  e;
            float error;
            int   i, j;

            for (int x = 0; x < source.PixelWidth; x++)
            {
                for (int y = 0; y < source.PixelHeight; y++)
                {
                    c   = source[x, y];
                    bOw = c.BlacOrWite();
                    targetImage[x, y] = bOw;
                    error             = c.R - targetImage[x, y].R;
                    e    = (byte)Math.Abs(error);
                    eCol = Color.FromRgb(e, e, e);
                    for (i = -1; i < 2; i++)
                    {
                        for (j = -1; j < 2; j++)
                        {
                            if (error > 0)
                            {
                                source[x + i, y + j] = Color.Add(source[x + i, y + j], Color.Multiply(eCol, filter[i + 1, j + 1]));
                            }
                            else
                            {
                                source[x + i, y + j] = Color.Subtract(source[x + i, y + j], Color.Multiply(eCol, filter[i + 1, j + 1]));
                            }
                        }
                    }
                }
            }
        }
Exemple #9
0
        private Brush GetCellFillBrush(double APct)
        {
            if ((FSortGaudeGradient == null) || (FSortGaudeGradient.Length == 0))
            {
                return(SystemColors.HighlightBrush);
            }
            Color cl = Colors.Transparent;

            for (int i = 1; i < FSortGaudeGradient.Length; i++)
            {
                if (FSortGaudeGradient[i].Offset == APct)
                {
                    cl = FSortGaudeGradient[i].Color;
                    break;
                }
                if ((FSortGaudeGradient[i - 1].Offset <= APct) && (FSortGaudeGradient[i].Offset > APct))
                {
                    double delta  = FSortGaudeGradient[i].Offset - FSortGaudeGradient[i - 1].Offset;
                    float  cl1pct = (float)(1 - (APct - FSortGaudeGradient[i - 1].Offset) / delta);
                    float  cl2pct = (float)(1 - (FSortGaudeGradient[i].Offset - APct) / delta);

                    Color cl1 = Color.Multiply(FSortGaudeGradient[i - 1].Color, cl1pct);
                    Color cl2 = Color.Multiply(FSortGaudeGradient[i].Color, cl2pct);
                    cl = Color.Add(cl1, cl2);
                    break;
                }
            }
            var b = new SolidColorBrush(cl);

            b.Freeze();
            return(b);
        }
        /// <summary>
        /// Gets the color through interpolation.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="max">The maximum.</param>
        /// <param name="alpha">The alpha.</param>
        /// <returns>Color.</returns>
        public static Color GetColor(int count, int max, byte alpha)
        {
            float w1    = ((float)count) / max;
            Color color = Color.Add(Color.Multiply(AreaColors[0], w1), Color.Multiply(AreaColors[1], 1.0f - w1));

            color.A = alpha;
            return(color);
        }
Exemple #11
0
        /// <summary>
        /// Method to mix two <c>Color</c> objects at a given opacity
        /// </summary>
        /// <param name="i">
        /// Background <c>Color</c> object
        /// </param>
        /// <param name="foreground">
        /// Foreground <c>Color</c> object
        /// </param>
        /// <param name="opacity">
        /// Opacity value [0.0-1.0] of the overlayed foreground <c>Color</c> object
        /// </param>
        /// <returns>
        /// The mixed <c>Color</c> object
        /// </returns>
        public static Color Blend(this Color i, Color foreground, double opacity)
        {
            var difference = Color.Subtract(foreground, i);
            var opacityFlt = Convert.ToSingle(opacity);
            var delta      = Color.Multiply(difference, opacityFlt);
            var result     = Color.Add(i, delta);

            return(result);
        }
Exemple #12
0
        public void TestAddColor()
        {
            Color color    = Color.ByARGB(100, 100, 100, 100);
            Color newColor = Color.Add(color, color);

            Assert.AreEqual(newColor.Alpha, 200);
            Assert.AreEqual(newColor.Green, 200);
            Assert.AreEqual(newColor.Blue, 200);
            Assert.AreEqual(newColor.Red, 200);
        }
Exemple #13
0
        public static Color GetAverage(params Color[] colors)
        {
            Color output = CLEAR;

            foreach (Color color in colors)
            {
                output = output.Add(color);
            }
            return(output.Divide(colors.Length));
        }
Exemple #14
0
        public void AddColor(params int[] data)
        {
            var color1 = new Color(0);
            var color2 = new Color(data[0], data[1], data[2], data[3]);

            var result   = Color.Add(color1, color2).ValuesArray;
            var expected = data.Select(x => Color.Mod(x, 256));

            Assert.Equal(expected, result);
        }
Exemple #15
0
        public void CanAddColors()
        {
            //Given
            var a1             = new Color(3, 4, 5);
            var a2             = new Color(2, 3, 1);
            var expectedResult = new Color(5, 7, 6);
            //When

            //Then
            var result = a1.Add(a2);

            Assert.Equal(expectedResult, result);
        }
Exemple #16
0
        private void Dispatcher_timer_Tick(object sender, EventArgs e)
        {
            var now  = DateTime.Now;
            var diff = now - then;

            then            = now;
            time_remaining -= diff;
            if (time_remaining.TotalSeconds <= 0)
            {
                current_timer_index = ++current_timer_index % timer_sequence.Length;
                time_remaining      = timer_sequence[current_timer_index].time;
                outline.Dispatcher.BeginInvoke((Action)async delegate
                {
                    const int enlarge_to = 5;
                    for (int i = 1; i < enlarge_to; i++)
                    {
                        SetWidth(width * i);
                        await Task.Delay(120);
                    }
                    for (int i = enlarge_to; i > 0; i--)
                    {
                        SetWidth(width * i);
                        await Task.Delay(120);
                    }
                });
            }
            else
            {
                Color c         = default(Color);
                var   info      = timer_sequence[current_timer_index];
                var   color_arr = info.type == TimerTypes.Work ? work_colors : break_colors;

                var part_complete = (info.time.TotalSeconds - time_remaining.TotalSeconds) / info.time.TotalSeconds;
                var color_split   = color_arr.Length - 1;
                if (color_split > 0)
                {
                    var split_part    = color_split * part_complete;
                    var lower_index   = (int)split_part;
                    var color_diff    = split_part - lower_index;
                    var fadeout_color = Color.Multiply(color_arr[lower_index], 1 - (float)color_diff);
                    var fadein_color  = Color.Multiply(color_arr[lower_index + 1], (float)color_diff);
                    c = Color.Add(fadeout_color, fadein_color);
                }
                else if (color_split == 0)
                {
                    c = color_arr[0];
                }
                SetColor(c);
            }
        }
Exemple #17
0
        public void AddValue(int value)
        {
            var color = new Color(0);

            var result   = Color.Add(color, value).ValuesArray;
            var expected = new int[4];

            for (var i = 0; i < expected.Length; i++)
            {
                expected[i] = Color.Mod(value, 256);
            }

            Assert.Equal(expected, result);
        }
        private static Color FromMireds(Slider slider, double mireds)
        {
            double percent = (mireds - slider.Minimum) / (slider.Maximum - slider.Minimum);

            if (percent >= 0.5)
            {
                percent = 2 * (percent - 0.5);
                return(Color.Add(Color.Multiply(Colors.White, (float)(1 - percent)),
                                 Color.Multiply(Color.FromRgb(255, 160, 0), (float)percent)));
            }

            percent = 2 * percent;
            return(Color.Add(Color.Multiply(Color.FromRgb(166, 209, 255), (float)(1 - percent)),
                             Color.Multiply(Colors.White, (float)percent)));
        }
Exemple #19
0
        public void ColorAdd()
        {
            //Result Test Comparison Declarations
            Color brTest = new Color(255, 0, 255);
            Color byTest = new Color(255, 255, 255);
            Color rgTest = new Color(255, 128, 0);

            Color brResult = Color.Add(Color.Blue, Color.Red);
            Color byResult = Color.Add(Color.Blue, Color.Yellow);
            Color rgResult = Color.Add(Color.Red, Color.Green);

            Assert.AreEqual(brTest, brResult);
            Assert.AreEqual(byTest, byResult);
            Assert.AreEqual(rgTest, rgResult);
        }
        protected override LinearGradientBrush GetCurrentValueCore(LinearGradientBrush
                                                                   defaultOriginValue, LinearGradientBrush defaultDestinationValue,
                                                                   AnimationClock animationClock)
        {
            // check for length of from and to
            if (From.GradientStops.Count != To.GradientStops.Count)
            {
                return(From);
            }

            if (animationClock.CurrentProgress == null)
            {
                return(From);
            }

            LinearGradientBrush brush = new LinearGradientBrush();

            brush.StartPoint = From.StartPoint + ((To.StartPoint - From.StartPoint) *
                                                  (double)animationClock.CurrentProgress);
            brush.EndPoint = From.EndPoint + ((To.EndPoint - From.EndPoint) *
                                              (double)animationClock.CurrentProgress);

            // calc gradientstops
            for (int cnt = 0; cnt < From.GradientStops.Count; cnt++)
            {
                GradientStop stop1 = From.GradientStops[cnt];
                GradientStop stop2 = To.GradientStops[cnt];

                // calc color
                Color color1   = stop1.Color;
                Color color2   = stop2.Color;
                Color newColor = Color.Subtract(color2, color1);
                newColor = Color.Multiply(newColor,
                                          (float)animationClock.CurrentProgress);
                newColor = Color.Add(newColor, color1);

                // calc offset
                double offset1 = (double)stop1.Offset;
                double offset2 = (double)stop2.Offset;
                double offset  = offset1 + ((offset2 - offset1) *
                                            (double)animationClock.CurrentProgress);

                brush.GradientStops.Add(new GradientStop(newColor, offset));
            }
            return(brush);
        }
Exemple #21
0
        /// <summary>
        /// Creates a polygon with <see cref="PolygonVertex"/>, what allows colors hard coded.
        /// </summary>
        /// <param name="vertices"></param>
        public Polygon(ICollection <PolygonVertex> vertices) : base(PrimitiveType.TriangleFan)
        {
            foreach (var polygonVertex in vertices)
            {
                Color.Add(polygonVertex.Color);
                Vertex.Add(new Vector3(polygonVertex.Position.X, polygonVertex.Position.Y, 0));
            }

            UpdateBoundingBox();

            if (UVs.Active)
            {
                foreach (var vertex in vertices)
                {
                    AddUV(vertex.Position);
                }
            }
        }
Exemple #22
0
        public override void ApplyPreset(IPresetAware from, IPresetAware to, double percentage)
        {
            if (from is EurolitePMB8 ledFrom && to is EurolitePMB8 ledTarget && !Locked)
            {
                Strenght    = (byte)(ledFrom.Strenght + (ledTarget.Strenght - ledFrom.Strenght) * percentage);
                Sensitivity = (byte)(ledFrom.Sensitivity + (ledTarget.Sensitivity - ledFrom.Sensitivity) * percentage);
                Speed       = (byte)(ledFrom.Speed + (ledTarget.Speed - ledFrom.Speed) * percentage);
                Flash       = (byte)(ledFrom.Flash + (ledTarget.Flash - ledFrom.Flash) * percentage);
                Mode        = ledTarget.Mode;

                int     numberOfColors = Colors.Length;
                Color[] tmpColors      = new Color[numberOfColors];
                for (int i = 0; i < numberOfColors; i++)
                {
                    tmpColors[i] = Color.Add(ledFrom.Colors[i], Color.Multiply(Color.Subtract(ledTarget.Colors[i], ledFrom.Colors[i]), (float)percentage));
                }
                Colors = tmpColors;
            }
Exemple #23
0
    public void FadePixels()
    {
        var sprite  = gameObject.GetComponent <SpriteRenderer>().sprite;
        var texture = sprite.texture;

        var pixels = texture.GetPixels();

        var newarr = new Color[pixels.Length].ToList();

        foreach (var pixel in pixels)
        {
            var npxl = pixel;
            npxl.a = 0;

            newarr.Add(npxl);
        }

        texture.SetPixels(newarr.ToArray());
    }
Exemple #24
0
            public virtual void ReadChildData(BinaryReader reader)
            {
                int x = 0;

                _bitmap.ReadString(reader);
                for (x = 0; (x < _reflections.Count); x = (x + 1))
                {
                    Reflections.Add(new LensFlareReflectionBlockBlock());
                    Reflections[x].Read(reader);
                }
                for (x = 0; (x < _reflections.Count); x = (x + 1))
                {
                    Reflections[x].ReadChildData(reader);
                }
                for (x = 0; (x < _brightness.Count); x = (x + 1))
                {
                    Brightness.Add(new LensFlareScalarAnimationBlockBlock());
                    Brightness[x].Read(reader);
                }
                for (x = 0; (x < _brightness.Count); x = (x + 1))
                {
                    Brightness[x].ReadChildData(reader);
                }
                for (x = 0; (x < _color.Count); x = (x + 1))
                {
                    Color.Add(new LensFlareColorAnimationBlockBlock());
                    Color[x].Read(reader);
                }
                for (x = 0; (x < _color.Count); x = (x + 1))
                {
                    Color[x].ReadChildData(reader);
                }
                for (x = 0; (x < _rotation.Count); x = (x + 1))
                {
                    Rotation.Add(new LensFlareScalarAnimationBlockBlock());
                    Rotation[x].Read(reader);
                }
                for (x = 0; (x < _rotation.Count); x = (x + 1))
                {
                    Rotation[x].ReadChildData(reader);
                }
            }
Exemple #25
0
        /// <summary>
        ///   Method to mix two <see cref="Color"/> objects at a given opacity.
        /// </summary>
        /// <param name="this">
        ///   Background <see cref="Color"/> object.
        /// </param>
        /// <param name="foreground">
        ///   Foreground <see cref="Color"/> object.
        /// </param>
        /// <param name="opacity">
        ///   Opacity value [0.0-1.0] of the overlayed <see cref="Color"/> object.
        /// </param>
        /// <returns>
        ///   The mixed <see cref="Color"/> object.
        /// </returns>
        public static Color Blend(
            this Color @this,
            Color foreground,
            double percentage)
        {
            if (percentage.IsNotWithin((0d, 1d)))
            {
                throw new ArgumentOutOfRangeException(
                          nameof(percentage),
                          percentage,
                          "The percentage parameter must be between 0 and 1, inclusively.");
            }

            var difference = Color.Subtract(foreground, @this);
            var opacityFlt = Convert.ToSingle(percentage);
            var delta      = Color.Multiply(difference, opacityFlt);
            var result     = Color.Add(@this, delta);

            return(result);
        }
Exemple #26
0
        public virtual BitmapSource ToBitmap(int wallPx, int cellPx, bool[] pathsForShow)
        {
            BitmapSource source = base.ToBitmap(wallPx, cellPx);
            PixelFormat  pf     = PixelFormats.Bgra32;
            int          height = generator.height * (cellPx + wallPx) + wallPx;
            int          width  = generator.width * (cellPx + wallPx) + wallPx;
            int          stride = (width * pf.BitsPerPixel + 7) / 8;

            byte[] pixels = new byte[height * stride];
            source.CopyPixels(pixels, stride, 0);
            Color[] colors = new Color[pathsForShow.Length];
            Random  rand   = new Random();

            for (int i = 0; i < colors.Length; ++i)
            {
                colors[i].B = (byte)rand.Next(255);
                colors[i].G = (byte)rand.Next(255);
                colors[i].R = (byte)rand.Next(255);
                colors[i].A = 120;
            }
            for (int i = 0; i < pathsForShow.Length; ++i)
            {
                if (!pathsForShow[i])
                {
                    continue;
                }
                foreach (Point p in paths[i].path)
                {
                    for (int k = wallPx; k < wallPx + cellPx; ++k)
                    {
                        for (int l = wallPx; l < wallPx + cellPx; ++l)
                        {
                            Color prev = GetPixelColor(ref pixels, p.y, p.x, wallPx, cellPx, k, l, stride);
                            prev = Color.Add(prev, Color.Multiply(Color.Subtract(colors[i], prev), colors[i].ScA));
                            SetPixelColor(ref pixels, prev, p.y, p.x, wallPx, cellPx, k, l, stride);
                        }
                    }
                }
            }
            return(BitmapSource.Create(width, height, 96, 96, pf, null, pixels, stride));
        }
Exemple #27
0
        public ActionResult Create(string ColorOne, string ColorTwo)
        {
            Color colorOne = (Color)ColorConverter.ConvertFromString(ColorOne);
            Color colorTwo = (Color)ColorConverter.ConvertFromString(ColorTwo);

            Debug.WriteLine(colorOne);
            Debug.WriteLine(colorTwo);

            //Add the two colors
            Color newColor = Color.Add(colorOne, colorTwo);


            Debug.WriteLine(newColor);

            //Return all three colors in their own ViewBag
            ViewBag.NewColor = newColor;
            ViewBag.ColorA   = colorOne;
            ViewBag.ColorB   = colorTwo;

            return(View());
        }
Exemple #28
0
        private Color Execute(Color a, Color b, OperationType operation)
        {
            Color color;

            switch (operation)
            {
            case OperationType.Addition:
                color = a.Add(b);
                break;

            case OperationType.Subtraction:
                color = a.Subtract(b);
                break;

            default:
                color = DefaultColor;
                break;
            }

            color.A = 255; // transparency not supported

            return(color);
        }
Exemple #29
0
        public static Color Blend(this Color current, Color target, ColorBlend mode, float amount = 1)
        {
            var white = Color.white;
            var value = Color.cyan;
            Func <float, float, float> formula = null;

            if (mode.Matches("Balance"))
            {
                value = current;
                var luma       = current.GetLuminance();
                var otherLuma  = target.GetLuminance();
                var difference = (luma - otherLuma).Abs();
                if (difference <= 0.3f)
                {
                    value = current.Add(luma < 0.3f ? 0.5f : -0.5f);
                }
            }
            else if (mode.Matches("Darken"))
            {
                value = current.Min(target);
            }
            else if (mode.Matches("Multiply"))
            {
                value = current * target;
            }
            else if (mode.Matches("ColorBurn"))
            {
                var blend = current.Invert().Divide(target);
                value = blend.Invert();
            }
            else if (mode.Matches("LinearBurn"))
            {
                value = current + target - white;
            }
            else if (mode.Matches("DarkerColor"))
            {
            }
            else if (mode.Matches("Lighten"))
            {
                value = current.Max(target);
            }
            else if (mode.Matches("Screen"))
            {
                value = white - current.Invert() * target.Invert();
            }
            else if (mode.Matches("ColorDodge"))
            {
                value = current.Divide(target.Invert());
            }
            else if (mode.Matches("Add") || mode.Matches("LinearDodge"))
            {
                value = current + target;
            }
            else if (mode.Matches("LighterColor"))
            {
            }
            else if (mode.Matches("Overlay"))
            {
                formula = (a, b) => { return(a < 0.5f ? 2 * a * b : 1 - (2 * (1 - a) * (1 - b))); };
            }
            else if (mode.Matches("SoftLight"))
            {
                formula = (a, b) => { return(b < 0.5f ? 2 * a * b + a + a * (1 - 2 * b) : Math.Sqrt(a).ToFloat() * (2 * b - 1) + 2 * a * (1 - b)); };
            }
            else if (mode.Matches("HardLight"))
            {
            }
            else if (mode.MatchesAny("VividLight", "LinearLight", "PinLight"))
            {
                ColorBlend modeA = ColorBlend.ColorBurn;
                ColorBlend modeB = ColorBlend.ColorDodge;
                if (mode.Matches("LinearLight"))
                {
                    modeA = ColorBlend.LinearBurn;
                    modeB = ColorBlend.LinearDodge;
                }
                if (mode.Matches("PinLight"))
                {
                    modeA = ColorBlend.Darken;
                    modeB = ColorBlend.Lighten;
                }
                var blendA = current.Blend(2 * target, modeA);
                var blendB = current.Blend(2 * (target - (white * 0.5f)), modeB);
                value.r = target.r < 0.5f ? blendA.r : blendB.r;
                value.g = target.g < 0.5f ? blendA.g : blendB.g;
                value.b = target.b < 0.5f ? blendA.b : blendB.b;
            }
            else if (mode.Matches("HardMix"))
            {
                var blend = current.Blend(target, ColorBlend.VividLight);
                value.r = blend.r < 0.5f ? 0 : 1;
                value.g = blend.g < 0.5f ? 0 : 1;
                value.b = blend.b < 0.5f ? 0 : 1;
            }
            else if (mode.Matches("Difference"))
            {
                value = (current - target).Abs();
            }
            else if (mode.Matches("Exclusion"))
            {
                value = (current + target - 2.0f * current * target);
            }
            else if (mode.Matches("Subtract"))
            {
                value = target - current;
            }
            else if (mode.Matches("Divide"))
            {
                value = target.Divide(current);
            }
            else if (mode.Matches("Hue"))
            {
            }
            else if (mode.Matches("Saturation"))
            {
            }
            else if (mode.Matches("Color"))
            {
            }
            else if (mode.Matches("Luminosity"))
            {
            }
            if (!formula.IsNull())
            {
                value.r = formula(current.r, target.r);
                value.g = formula(current.g, target.g);
                value.b = formula(current.b, target.b);
            }
            return(current.Lerp(value.Saturate(), amount));
        }
Exemple #30
0
 public static Color Add(this Color current, float amount)
 {
     return(current.Add(new Color(amount, amount, amount)));
 }
 /// <summary>
 /// Linear color interpolation.
 /// </summary>
 public static Color Lerp(Color toColor, Color fromColor, float amount)
 {
     Color delta = toColor.Subtract(fromColor);
     delta = delta.Multiply(amount);
     return fromColor.Add(delta);
 }