Exemplo n.º 1
0
        /// <summary>
        /// Interpolates between two values using an enforced amount.
        /// </summary>
        public static float LerpExact(float a, float b, float amount)
        {
            if (!RangeF.Contains(0.0f, 1.0f, amount))
            {
                throw new ArithmeticException("Cannot interpolate with an amount outside the range of [0, 1].");
            }

            return((1.0f - amount) * a + amount * b);
        }
Exemplo n.º 2
0
        private static ImmutableColor CreateFromChmx(float c, float h, float m, float x)
        {
            float rF = 0.00f;
            float gF = 0.00f;
            float bF = 0.00f;

            if (RangeF.Contains(0.00f, 60.00f, h, true, false))
            {
                rF = c;
                gF = x;
                bF = 0;
            }
            else if (RangeF.Contains(60.00f, 120.00f, h, true, false))
            {
                rF = x;
                gF = c;
                bF = 0;
            }
            else if (RangeF.Contains(120.00f, 180.00f, h, true, false))
            {
                rF = 0;
                gF = c;
                bF = x;
            }
            else if (RangeF.Contains(180.00f, 240.00f, h, true, false))
            {
                rF = 0;
                gF = x;
                bF = c;
            }
            else if (RangeF.Contains(240.00f, 300.00f, h, true, false))
            {
                rF = x;
                gF = 0;
                bF = c;
            }
            else if (RangeF.Contains(300.00f, 360.00f, h, true, false))
            {
                rF = c;
                gF = 0;
                bF = x;
            }

            byte r = (byte)Math.Floor((rF + m) * 255);
            byte g = (byte)Math.Floor((gF + m) * 255);
            byte b = (byte)Math.Floor((bF + m) * 255);

            return(new ImmutableColor(r, g, b));
        }