Esempio n. 1
0
        // RGBをHSVに変換
        public static HSV RGB2HSV(RGB RGB)
        {
            HSV hsv = new HSV();

            double max = Math.Max(Math.Max(RGB.R, RGB.G), RGB.B);
            double min = Math.Min(Math.Min(RGB.R, RGB.G), RGB.B);

            hsv.V = (int)max;

            if (max == min)
            {
                hsv.H = 0;
                hsv.S = 0;
            }
            else
            {
                hsv.S = (int)(((max - min) * 255) / max);

                hsv.H = 0;

                if (max == RGB.R)
                {
                    hsv.H = (int)(60 * (RGB.G - RGB.B) / (max - min));
                }
                else if (max == RGB.G)
                {
                    hsv.H = (int)(60 * (2 + (RGB.B - RGB.R) / (max - min)));
                }
                else if (max == RGB.B)
                {
                    hsv.H = (int)(60 * (4 + (RGB.R - RGB.G) / (max - min)));
                }

                if (hsv.H < 0)
                {
                    hsv.H += 360;
                }
            }
            return(hsv);
        }
Esempio n. 2
0
        override public void SetLed(double x, double y, double z, RGB color)
        {
            var hsv = new HSV((int)(360 * (0.8 - z / LED.DEPTH)), 360, 360);

            base.SetLed(x, y, z, Util.HSV2RGB(hsv.H, hsv.S, hsv.V, color.A));
        }