Exemplo n.º 1
0
        /// <summary>
        /// Returns a gradient that represents a linear interpolation between two colors.
        /// </summary>
        /// <param name="color1">The left end of the gradient.</param>
        /// <param name="color2">The right end of the gradient.</param>
        /// <returns>A GradientHSL that represents a linear interpolation between color1 and color2.</returns>
        public static GradientHSL GetLerp(ColorHSL color1, ColorHSL color2)
        {
            var gradient = new GradientHSL();

            var leftColorKey = new GradientHSLColorKey(color1, 0);
            var rightColorKey = new GradientHSLColorKey(color2, 1);

            gradient.SetKeys(
                new[] { leftColorKey, rightColorKey });

            return gradient;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a gradient that represents a linear interpolation between two colors.
        /// </summary>
        /// <param name="color1"></param>
        /// <param name="color2"></param>
        /// <returns></returns>
        public static GradientHSL GetLerp(ColorHSL color1, ColorHSL color2)
        {
            var gradient = new GradientHSL {curve = ResponseCurveHSL.GetLerp(0, 1, color1, color2)};

            return gradient;
        }
Exemplo n.º 3
0
 public GradientHSLColorKey(ColorHSL color, float time)
 {
     this.color = color;
     this.time = time;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Linearly interpolates between the given colors in HSL color space.
        /// </summary>
        /// <param name="color1"></param>
        /// <param name="color2"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public static ColorHSL Lerp(ColorHSL color1, ColorHSL color2, float t)
        {
            if (Math.Abs(color1.S) < Tolerance || Math.Abs(color1.L) < Tolerance)
            {
                var newH = color2.H;
                var newS = Mathf.Lerp(color1.S, color2.S, t);
                var newL = Mathf.Lerp(color1.L, color2.L, t);

                var newColor = new ColorHSL(newH, newS, newL);

                return newColor;
            }
            //else
            if (Math.Abs(color2.S) < Tolerance || Math.Abs(color2.L) < Tolerance)
            {
                var newH = color1.H;
                var newS = Mathf.Lerp(color1.S, color2.S, t);
                var newL = Mathf.Lerp(color1.L, color2.L, t);

                var newColor = new ColorHSL(newH, newS, newL);

                return newColor;
            }
            //else
            {
                var newH = GLMathf.Wlerp01(color1.H, color2.H, t);
                var newS = Mathf.Lerp(color1.S, color2.S, t);
                var newL = Mathf.Lerp(color1.L, color2.L, t);

                var newColor = new ColorHSL(newH, newS, newL);

                return newColor;
            }
        }
Exemplo n.º 5
0
        /**
            Generates a list of colors. For each color, HSL values are chosen randomly.

            @param colorCount The number of colors to generate.
        */
        public static List<Color> GenerateUniformHSL(int colorCount)
        {
            var colors = new List<Color>();

            for (int i = 0; i < colorCount; i++)
            {
                var newColor = new ColorHSL(Random.value, Random.value, Random.value);

                colors.Add(newColor.Color);
            }

            return colors;
        }
Exemplo n.º 6
0
        /**
            Generates a list of colours with given hue, random saturation and random luminance
        */
        public static List<Color> GenerateRandomSaturationLuminance(int colorCount, float hue)
        {
            var colors = new List<Color>();

            for (int i = 0; i < colorCount; i++)
            {
                var hslColor = new ColorHSL(hue, Random.value, Random.value);

                colors.Add(hslColor.Color);
            }

            return colors;
        }
Exemplo n.º 7
0
        /**
            Generates a color with random hue in the given range, given saturation and given luminance.
        */
        public static List<Color> GenerateRandomHueInRange(int colorCount, float startHue, float endHue, float saturation, float luminance)
        {
            var colors = new List<Color>();
            var hueRange = endHue - startHue;

            if(hueRange < 0)
            {
                hueRange += 1.0f;
            }

            for (int i = 0; i < colorCount; i++)
            {
                var newHue = hueRange * Random.value + startHue;

                if(newHue > 1.0)
                {
                    newHue -= 1.0f;
                }

                var hslColor = new ColorHSL(newHue, saturation, luminance);

                colors.Add(hslColor.Color);
            }

            return colors;
        }
Exemplo n.º 8
0
        public static List<Color> GenerateHarmony(int colorCount, float referenceAngle, float offsetAngle1, float offsetAngle2, float rangeAngle0,
			float rangeAngle1, float rangeAngle2, float saturation, float saturationRange, float luminance, float luminanceRange)
        {
            var colors = new List<Color>();
            for (int i = 0; i < colorCount; i++)
            {
                var randomAngle = Random.value*(rangeAngle0 + rangeAngle1 + rangeAngle2);

                if (randomAngle > rangeAngle0)
                {
                    if (randomAngle < rangeAngle0 + rangeAngle1)
                    {
                        randomAngle += offsetAngle1;
                    }
                    else
                    {
                        randomAngle += offsetAngle2;
                    }
                }

                var newSaturation = saturation + (Random.value - 0.5f)*saturationRange;
                var newLuminance = luminance + +(Random.value - 0.5f)*luminanceRange;

                var hslColor = new ColorHSL(((referenceAngle + randomAngle)/360.0f)%1.0f, newSaturation, newLuminance);

                colors.Add(hslColor.Color);
            }

            return colors;
        }