Example #1
0
        public static Texture2D GenerateRainbowGradient(int texWidth, int texHeight)
        {
            Texture2D tex = new Texture2D(texWidth, texHeight, TextureFormat.ARGB32, false, false);

            Color c;

            //int xAlphaEnd = (int)Mathf.Round(color.a * (float)texWidth);
            for (int x = 0; x < texWidth; x++)
            {
                c = HSBColor.ToColor(new HSBColor((float)x / (float)texWidth, 1f, 1f));
                for (int y = 0; y < texHeight; y++)
                {
                    tex.SetPixel(x, y, c);
                }
            }
            tex.Apply();
            return(tex);
        }
Example #2
0
        public static Texture2D GenerateColorField(int texWidth, int texHeight, Color targetColor)
        {
            Texture2D tex = new Texture2D(texWidth, texHeight, TextureFormat.ARGB32, false, false);
            HSBColor  hue = new HSBColor(targetColor);
            Color     c;

            //int xAlphaEnd = (int)Mathf.Round(color.a * (float)texWidth);
            for (int x = 0; x < texWidth; x++)
            {
                for (int y = 0; y < texHeight; y++)
                {
                    c = new HSBColor(hue.h, (float)x / (float)texWidth, (float)y / (float)texHeight).ToColor();
                    tex.SetPixel(x, y, c);
                }
            }
            tex.Apply();
            return(tex);
        }
Example #3
0
        public static HSBColor Lerp(HSBColor a, HSBColor b, float t)
        {
            float h, s;

            //check special case black (color.b==0): interpolate neither hue nor saturation!
            //check special case grey (color.s==0): don't interpolate hue!
            if (a.b == 0)
            {
                h = b.h;
                s = b.s;
            }
            else if (b.b == 0)
            {
                h = a.h;
                s = a.s;
            }
            else
            {
                if (a.s == 0)
                {
                    h = b.h;
                }
                else if (b.s == 0)
                {
                    h = a.h;
                }
                else
                {
                    // works around bug with LerpAngle
                    float angle = Mathf.LerpAngle(a.h * 360f, b.h * 360f, t);
                    while (angle < 0f)
                    {
                        angle += 360f;
                    }
                    while (angle > 360f)
                    {
                        angle -= 360f;
                    }
                    h = angle / 360f;
                }
                s = Mathf.Lerp(a.s, b.s, t);
            }
            return(new HSBColor(h, s, Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t)));
        }