Example #1
0
        public override SKColor GetColor(ArtemisLed led, SKPoint renderPoint)
        {
            SKColor       mainColor     = Properties.MainColor.CurrentValue;
            SKColor       secondColor   = Properties.SecondaryColor.CurrentValue;
            ColorGradient gradientColor = Properties.GradientColor.CurrentValue;
            SKSize        scale         = Properties.Scale.CurrentValue;
            float         hardness      = Properties.Hardness.CurrentValue / 50f;

            float scrolledX = renderPoint.X + _x;

            if (float.IsNaN(scrolledX) || float.IsInfinity(scrolledX))
            {
                scrolledX = 0;
            }
            float scrolledY = renderPoint.Y + _y;

            if (float.IsNaN(scrolledY) || float.IsInfinity(scrolledY))
            {
                scrolledY = 0;
            }

            float width  = 1f / (MathF.Max(scale.Width, 0.001f) / 100f);
            float height = 1f / (MathF.Max(scale.Height, 0.001f) / 100f);

            float evalX = scrolledX * (width / 40f);
            float evalY = scrolledY * (height / 40f);

            float v      = (float)_noise.Evaluate(evalX, evalY, _z) * hardness;
            float amount = Math.Max(0f, Math.Min(1f, v));

            if (Properties.ColorType.BaseValue == ColorMappingType.Simple)
            {
                return(mainColor.Interpolate(secondColor, amount));
            }
            if (gradientColor != null && _colorMap.Length == 101)
            {
                return(_colorMap[(int)Math.Round(amount * 100, MidpointRounding.AwayFromZero)]);
            }
            return(SKColor.Empty);
        }