Пример #1
0
        public static HSVColor rgbToHsv(Color32 color)
        {
            HSVColor result=new HSVColor();
            float min,max,delta;
            float r = (float)color.r/255.0f;
            float g = (float)color.g/255.0f;
            float b = (float)color.b/255.0f;

            min = Mathf.Min(r,g,b);
            max = Mathf.Max(r,g,b);
            result.v = max;
            delta = max - min;

            if( max != 0 )
                result.s = delta / max;		// s
            else {
                // r = g = b = 0		// s = 0, v is undefined
                result.s = 0;
                result.h = -1;
                return result;
            }
            if( r == max )
                result.h = ( g - b ) / delta;		// between yellow & magenta
            else if( g == max )
                result.h = 2 + ( b - r ) / delta;	// between cyan & yellow
            else
                result.h = 4 + ( r - g ) / delta;	// between magenta & cyan
            result.h *= 60;				// degrees
            if( result.h < 0 )
                result.h += 360;
            result.h /=360;
            return result;
        }
Пример #2
0
 public HSVColor getHSV()
 {
     float x = lastPosition.x -  paletteRect.x;
     float y = lastPosition.y - paletteRect.y;
     HSVColor c = new HSVColor();
     c.h = (float)currentHue / hueSliderRect.height;
     c.s = x / paletteRect.width;
     c.v = 1 - y / paletteRect.height;
     return c;
 }
        public HSVColor getHSV()
        {
            float    x = lastPosition.x - paletteRect.x;
            float    y = lastPosition.y - paletteRect.y;
            HSVColor c = new HSVColor();

            c.h = (float)currentHue / hueSliderRect.height;
            c.s = x / paletteRect.width;
            c.v = 1 - y / paletteRect.height;
            return(c);
        }
Пример #4
0
        public static HSVColor rgbToHsv(Color32 color)
        {
            HSVColor result = new HSVColor();
            float    min, max, delta;
            float    r = (float)color.r / 255.0f;
            float    g = (float)color.g / 255.0f;
            float    b = (float)color.b / 255.0f;

            min      = Mathf.Min(r, g, b);
            max      = Mathf.Max(r, g, b);
            result.v = max;
            delta    = max - min;

            if (max != 0)
            {
                result.s = delta / max;                         // s
            }
            else
            {
                // r = g = b = 0		// s = 0, v is undefined
                result.s = 0;
                result.h = -1;
                return(result);
            }
            if (r == max)
            {
                result.h = (g - b) / delta;                             // between yellow & magenta
            }
            else if (g == max)
            {
                result.h = 2 + (b - r) / delta;                         // between cyan & yellow
            }
            else
            {
                result.h = 4 + (r - g) / delta;                 // between magenta & cyan
            }
            result.h *= 60;                                     // degrees
            if (result.h < 0)
            {
                result.h += 360;
            }
            result.h /= 360;
            return(result);
        }
        public void setRGBColor(Color32 color)
        {
            float h, s, v;

            currentRGBColor = color;
            if (baseHue)
            {
                ColorUtil.RGBToHSV((Color)color, out h, out s, out v);
            }
            else
            {
                ColorUtil.RGBToHSV((Color)color, out s, out v, out h);
            }

            currentHSVColor = new HSVColor(h, s, v);
            currentHue      = (int)(hueSliderRect.height * h);

            updatePaletteTexture();
            calculateActiveColorPosition(new Vector2(paletteRect.x + paletteRect.width * s,
                                                     paletteRect.y + paletteRect.height * (1 - v)));
        }
Пример #6
0
 // h - 0->1
 // s  0->1
 // v  0-> 1
 public static Color32 hsvToRgb(HSVColor hsvColor)
 {
     return hsvToRgb(hsvColor.h,hsvColor.s,hsvColor.v);
 }
 void recalculateHsvAndRGB()
 {
     currentHSVColor = getHSV();
     currentRGBColor = getRGB(currentHSVColor);
 }
 public Color32 getRGB(HSVColor c = null)
 {
     return(ColorUtil.hsvToRgb(c == null ? currentHSVColor : c));
 }
Пример #9
0
        // h - 0->1
        // s  0->1
        // v  0-> 1

        public static Color32 hsvToRgb(HSVColor hsvColor)
        {
            return(hsvToRgb(hsvColor.h, hsvColor.s, hsvColor.v));
        }
Пример #10
0
 public Color32 getRGB(HSVColor c = null)
 {
     return ColorUtil.hsvToRgb(c==null ? currentHSVColor : c);
 }
Пример #11
0
 void recalculateHsvAndRGB()
 {
     currentHSVColor = getHSV();
     currentRGBColor = getRGB(currentHSVColor);
 }
Пример #12
0
        public void setRGBColor(Color32 color)
        {
            float h,s,v;
            currentRGBColor = color;
            if (baseHue)
                ColorUtil.RGBToHSV((Color)color,out h,out s,out v);
            else
                ColorUtil.RGBToHSV((Color)color,out s,out v,out h);

            currentHSVColor = new HSVColor(h,s,v);
            currentHue = (int)(hueSliderRect.height * h);

            updatePaletteTexture();
            calculateActiveColorPosition(new Vector2(paletteRect.x + paletteRect.width  * s,
                                                     paletteRect.y + paletteRect.height * (1 - v)));
        }