Пример #1
0
        private static Color[] ShiftHue(Color[] colorArray, Color targetColor, int count, bool isZora, bool isGradient, bool isFierceDeity)
        {
            Color[] shiftedColors = new Color[count];
            Color   averageColor;

            if (isZora && !isGradient)
            {
                averageColor = ColorUtils.GetAverageColour(colorArray, 16);
            }
            else
            {
                averageColor = ColorUtils.GetAverageColour(colorArray, count);
            }
            float hueRotation       = targetColor.GetHue() - averageColor.GetHue();
            float averageBrightness = averageColor.GetBrightness();
            float averageSaturation = averageColor.GetSaturation();

            for (int i = 0; i < count; i++)
            {
                if ((i == 12) && (count == 14))
                {
                    shiftedColors[i] = colorArray[i];
                    continue;
                }
                float hue        = colorArray[i].GetHue();
                float brightness = colorArray[i].GetBrightness();
                float saturation = colorArray[i].GetSaturation();
                brightness -= averageBrightness;
                saturation -= averageSaturation;
                brightness += targetColor.GetBrightness();
                saturation += targetColor.GetSaturation();
                hue        += hueRotation;
                if (isFierceDeity)
                {
                    saturation = targetColor.GetSaturation();
                    hue        = targetColor.GetHue();
                }
                if (isZora && isGradient)
                {
                    if (i > 351)
                    {
                        float x0 = colorArray[352].GetBrightness();
                        float x1 = colorArray[511].GetBrightness();
                        float x  = colorArray[i].GetBrightness();
                        hue        = targetColor.GetHue();
                        saturation = targetColor.GetSaturation();
                        brightness = Interpolate(targetColor.GetBrightness(), colorArray[511].GetBrightness(), x0, x1, x);
                    }
                }
                ColorUtils.ValidateHSB(ref hue, ref saturation, ref brightness);
                shiftedColors[i] = ColorUtils.FromAHSB(colorArray[i].A, hue, saturation, brightness);
                //this code is a mess
                if (isZora && isGradient)
                {
                    if (i < 96)
                    {
                        shiftedColors[i] = colorArray[i];
                    }
                    else if (i < 352)
                    {
                        float x0 = colorArray[95].GetBrightness();
                        float x1 = colorArray[352].GetBrightness();
                        float x  = colorArray[i].GetBrightness();
                        int   rr = (int)Interpolate(colorArray[95].R, targetColor.R, x0, x1, x);
                        int   gg = (int)Interpolate(colorArray[95].G, targetColor.G, x0, x1, x);
                        int   bb = (int)Interpolate(colorArray[95].B, targetColor.B, x0, x1, x);
                        ColorUtils.ValidateRGB(ref rr, ref gg, ref bb);
                        shiftedColors[i] = Color.FromArgb(rr, gg, bb);
                    }
                }
                else if (isZora)
                {
                    if (i > 15)
                    {
                        float x0 = colorArray[14].GetBrightness();
                        float x1 = colorArray[31].GetBrightness();
                        float x  = colorArray[i].GetBrightness();
                        int   rr = (int)Interpolate(shiftedColors[14].R, colorArray[31].R, x0, x1, x);
                        int   gg = (int)Interpolate(shiftedColors[14].G, colorArray[31].G, x0, x1, x);
                        int   bb = (int)Interpolate(shiftedColors[14].B, colorArray[31].B, x0, x1, x);
                        ColorUtils.ValidateRGB(ref rr, ref gg, ref bb);
                        shiftedColors[i] = Color.FromArgb(rr, gg, bb);
                    }
                }
            }
            return(shiftedColors);
        }