Beispiel #1
0
        public static Color GetRelativeColor(this GradientStopCollection gsc, double offset)
        {
            GradientStop before = gsc.Where(w => w.Offset == gsc.Min(m => m.Offset)).First();
            GradientStop after  = gsc.Where(w => w.Offset == gsc.Max(m => m.Offset)).First();

            foreach (var gs in gsc)
            {
                if (gs.Offset < offset && gs.Offset > before.Offset)
                {
                    before = gs;
                }
                if (gs.Offset > offset && gs.Offset < after.Offset)
                {
                    after = gs;
                }
            }

            var color = new Color();

            color.ScA = (float)((offset - before.Offset) * (after.Color.ScA - before.Color.ScA) / (after.Offset - before.Offset) + before.Color.ScA);
            color.ScR = (float)((offset - before.Offset) * (after.Color.ScR - before.Color.ScR) / (after.Offset - before.Offset) + before.Color.ScR);
            color.ScG = (float)((offset - before.Offset) * (after.Color.ScG - before.Color.ScG) / (after.Offset - before.Offset) + before.Color.ScG);
            color.ScB = (float)((offset - before.Offset) * (after.Color.ScB - before.Color.ScB) / (after.Offset - before.Offset) + before.Color.ScB);

            return(color);
        }
Beispiel #2
0
        private Color EvaluateGradient(double offset)
        {
            // Praise be to StackOverflow

            // https://stackoverflow.com/questions/9650049/get-color-in-specific-location-on-gradient

            GradientStop before = _hpGradient.Where(w => w.Offset == _hpGradient.Min(m => m.Offset)).First();
            GradientStop after  = _hpGradient.Where(w => w.Offset == _hpGradient.Max(m => m.Offset)).First();

            foreach (GradientStop gs in _hpGradient)
            {
                if (gs.Offset < offset && gs.Offset > before.Offset)
                {
                    before = gs;
                }
                if (gs.Offset > offset && gs.Offset < after.Offset)
                {
                    after = gs;
                }
            }

            Color color = new Color
            {
                ScA = (float)((offset - before.Offset) * (after.Color.ScA - before.Color.ScA) / (after.Offset - before.Offset) + before.Color.ScA),
                ScR = (float)((offset - before.Offset) * (after.Color.ScR - before.Color.ScR) / (after.Offset - before.Offset) + before.Color.ScR),
                ScG = (float)((offset - before.Offset) * (after.Color.ScG - before.Color.ScG) / (after.Offset - before.Offset) + before.Color.ScG),
                ScB = (float)((offset - before.Offset) * (after.Color.ScB - before.Color.ScB) / (after.Offset - before.Offset) + before.Color.ScB)
            };

            return(color);
        }
Beispiel #3
0
        private Color GetRelativeColor(GradientStopCollection gsc, double offset)
        {
            GradientStop before = gsc.Where(w => w.Offset == gsc.Min(m => m.Offset)).First();
            GradientStop after  = gsc.Where(w => w.Offset == gsc.Max(m => m.Offset)).First();

            foreach (var gs in gsc)
            {
                if (gs.Offset < offset && gs.Offset > before.Offset)
                {
                    before = gs;
                }
                if (gs.Offset > offset && gs.Offset < after.Offset)
                {
                    after = gs;
                }
            }

            var color = new System.Windows.Media.Color
            {
                ScA = (float)((offset - before.Offset) * (after.Color.ScA - before.Color.ScA) / (after.Offset - before.Offset) + before.Color.ScA),
                ScR = (float)((offset - before.Offset) * (after.Color.ScR - before.Color.ScR) / (after.Offset - before.Offset) + before.Color.ScR),
                ScG = (float)((offset - before.Offset) * (after.Color.ScG - before.Color.ScG) / (after.Offset - before.Offset) + before.Color.ScG),
                ScB = (float)((offset - before.Offset) * (after.Color.ScB - before.Color.ScB) / (after.Offset - before.Offset) + before.Color.ScB)
            };

            return(color);
        }
        public static Color GetRelativeColor(this GradientStopCollection gsc, double offset, float alpha)
        {
            var point = gsc.SingleOrDefault(x => x.Offset == offset);

            if (point != null)
            {
                return(point.Color);
            }

            GradientStop before = gsc.Where(x => x.Offset == gsc.Min(m => m.Offset)).First();
            GradientStop after  = gsc.Where(x => x.Offset == gsc.Max(m => m.Offset)).First();

            foreach (var gs in gsc)
            {
                if (gs.Offset < offset && gs.Offset > before.Offset)
                {
                    before = gs;
                }
                if (gs.Offset > offset && gs.Offset < after.Offset)
                {
                    after = gs;
                }
            }

            var color = new Color();

            color.ScR = (float)((offset - before.Offset) * (after.Color.ScR - before.Color.ScR) / (after.Offset - before.Offset) + before.Color.ScR);
            color.ScG = (float)((offset - before.Offset) * (after.Color.ScG - before.Color.ScG) / (after.Offset - before.Offset) + before.Color.ScG);
            color.ScB = (float)((offset - before.Offset) * (after.Color.ScB - before.Color.ScB) / (after.Offset - before.Offset) + before.Color.ScB);

            if (alpha >= 0 && alpha <= 1)
            {
                color.ScA = alpha;
            }
            else
            {
                color.ScA = (float)((offset - before.Offset) * (after.Color.ScA - before.Color.ScA) / (after.Offset - before.Offset) + before.Color.ScA);
            }

            return(color);
        }
        private Color GetRelativeColor(GradientStopCollection gsc, double offset)
        {
            GradientStop before = gsc.Where(w => w.Offset == gsc.Min(m => m.Offset)).First();
            GradientStop after = gsc.Where(w => w.Offset == gsc.Max(m => m.Offset)).First();

            foreach (var gs in gsc)
            {
                if (gs.Offset < offset && gs.Offset > before.Offset)
                {
                    before = gs;
                }
                if (gs.Offset > offset && gs.Offset < after.Offset)
                {
                    after = gs;
                }
            }

            var color = new Color();
            color.ScA = (float)((offset - before.Offset) * (after.Color.ScA - before.Color.ScA) / (after.Offset - before.Offset) + before.Color.ScA);
            color.ScR = (float)((offset - before.Offset) * (after.Color.ScR - before.Color.ScR) / (after.Offset - before.Offset) + before.Color.ScR);
            color.ScG = (float)((offset - before.Offset) * (after.Color.ScG - before.Color.ScG) / (after.Offset - before.Offset) + before.Color.ScG);
            color.ScB = (float)((offset - before.Offset) * (after.Color.ScB - before.Color.ScB) / (after.Offset - before.Offset) + before.Color.ScB);
            return color;
        }
Beispiel #6
0
        private void ChangeColorForGradation()
        {
            GradientStopCollection col = new GradientStopCollection();

            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 255, G = 120, B = 120
            }, 1));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 255, G = 105, B = 105
            }, 0.95));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 255, G = 90, B = 90
            }, 0.90));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 255, G = 75, B = 75
            }, 0.85));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 255, G = 60, B = 60
            }, 0.80));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 255, G = 45, B = 45
            }, 0.75));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 255, G = 30, B = 30
            }, 0.70));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 255, G = 15, B = 15
            }, 0.65));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 255, G = 0, B = 0
            }, 0.60));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 245, G = 0, B = 0
            }, 0.55));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 235, G = 0, B = 0
            }, 0.50));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 225, G = 0, B = 0
            }, 0.45));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 215, G = 0, B = 0
            }, 0.40));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 205, G = 0, B = 0
            }, 0.35));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 195, G = 0, B = 0
            }, 0.30));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 185, G = 0, B = 0
            }, 0.25));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 175, G = 0, B = 0
            }, 0.20));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 165, G = 0, B = 0
            }, 0.15));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 155, G = 0, B = 0
            }, 0.10));
            col.Add(new GradientStop(new Color()
            {
                A = 100, R = 145, G = 0, B = 0
            }, 0.05));

            GradientStopCollection bigCol = new GradientStopCollection();

            bigCol.Add(new GradientStop(new Color()
            {
                A = 100, R = 178, G = 0, B = 0
            }, 0));
            bigCol.Add(new GradientStop(new Color()
            {
                A = 100, R = 251, G = 171, B = 171
            }, 1));
            bigCol.Add(new GradientStop(new Color()
            {
                A = 100, R = 226, G = 10, B = 10
            }, 0.233));
            bigCol.Add(new GradientStop(new Color()
            {
                A = 100, R = 220, G = 33, B = 33
            }, 0.44));
            bigCol.Add(new GradientStop(new Color()
            {
                A = 100, R = 216, G = 83, B = 83
            }, 0.61));
            bigCol.Add(new GradientStop(new Color()
            {
                A = 100, R = 209, G = 7, B = 7
            }, 0.117));
            bigCol.Add(new GradientStop(new Color()
            {
                A = 100, R = 218, G = 25, B = 25
            }, 0.363));
            bigCol.Add(new GradientStop(new Color()
            {
                A = 100, R = 240, G = 118, B = 118
            }, 0.76));
            switch (SoulData.CurrentGradation)
            {
            case 5:
                mainCircle.Fill = new RadialGradientBrush(col.Where(color => col.IndexOf(color) % 4 == 0).ToGradientStopCollection());
                break;

            case 10:
                mainCircle.Fill = new RadialGradientBrush(col.Where(color => col.IndexOf(color) % 2 == 0).ToGradientStopCollection());
                break;

            case 20:
                mainCircle.Fill = new RadialGradientBrush(col);
                break;

            default:
                mainCircle.Fill = new RadialGradientBrush(bigCol);
                break;
            }
        }