Example #1
0
        private void Update(EvaluationContext context)
        {
            var blendMode = (BlendModes)BlendMode.GetValue(context);
            var gradientA = GradientA.GetValue(context);
            var gradientB = GradientB.GetValue(context);
            var mixFactor = MixFactor.GetValue(context).Clamp(0, 1);

            _steps.Clear();
            foreach (var stepA in gradientA.Steps)
            {
                var positionA    = stepA.NormalizedPosition;
                var colorA       = stepA.Color;
                var colorB       = gradientB.Sample(positionA);
                var blendedColor = BlendColors(colorA, colorB, blendMode, mixFactor);
                _steps[positionA] = blendedColor;
            }

            foreach (var stepB in gradientB.Steps)
            {
                var positionB    = stepB.NormalizedPosition;
                var colorB       = stepB.Color;
                var colorA       = gradientA.Sample(positionB);
                var blendedColor = BlendColors(colorA, colorB, blendMode, mixFactor);
                _steps[positionB] = blendedColor;
            }

            var positions = _steps.Keys.ToArray();
            var steps     = new List <Gradient.Step>(positions.Length);

            Array.Sort(positions);

            foreach (var p in positions)
            {
                steps.Add(new Gradient.Step()
                {
                    Color = _steps[p],
                    Id    = new Guid(),
                    NormalizedPosition = p,
                });
            }

            var result = new Gradient()
            {
                Steps         = steps,
                Interpolation = Gradient.Interpolations.Linear,
            };

            Result.Value = result;
        }