Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# Color Convert

public static void ColorToHSV(Color color, out double hue, out double saturation, out double value)
{
    int max = Math.Max(color.R, Math.Max(color.G, color.B));
    int min = Math.Min(color.R, Math.Min(color.G, color.B));

    hue = color.GetHue();
    saturation = (max == 0) ? 0 : 1d - (1d * min / max);
    value = max / 255d;
}

public static Color ColorFromHSV(double hue, double saturation, double value)
{
    int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
    double f = hue / 60 - Math.Floor(hue / 60);

    value = value * 255;
    int v = Convert.ToInt32(value);
    int p = Convert.ToInt32(value * (1 - saturation));
    int q = Convert.ToInt32(value * (1 - f * saturation));
    int t = Convert.ToInt32(value * (1 - (1 - f) * saturation));

    if (hi == 0)
        return Color.FromArgb(255, v, t, p);
    else if (hi == 1)
        return Color.FromArgb(255, q, v, p);
    else if (hi == 2)
        return Color.FromArgb(255, p, v, t);
    else if (hi == 3)
        return Color.FromArgb(255, p, q, v);
    else if (hi == 4)
        return Color.FromArgb(255, t, p, v);
    else
        return Color.FromArgb(255, v, p, q);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: trigger enter with nav mesh 
Csharp :: unity AppDomain 
Csharp :: gersener waves 
Csharp :: unity rotatetowards 
Csharp :: c# (sharp) varibles 
Csharp :: what is vector3.one c# 
Csharp :: generate an mvc controller when dotnet core command line 
Csharp :: check if app have administrator rights c# 
Csharp :: C# list of unique values with group and counts 
Csharp :: how to download things c# 
Csharp :: openiddect ef core table not creating 
Csharp :: How to put a (new line) inside a list box 
Csharp :: Library dll unless netloaded by AutoCAD 
Csharp :: save checkbox value to database c# 
Csharp :: c# convert 1 to 01 
Csharp :: in model add to give drop down message 
Csharp :: c# open config file by path 
Csharp :: player movement script unity 
Csharp :: c# call by reference 
Csharp :: how to make projectile track and go to specified enemy in unity 
Csharp :: how to oppen a site using c# 
Csharp :: Transparent UserControl 
Csharp :: how to select class object from query c# 
Csharp :: grass download for unityh 
Csharp :: sqldatareader get row count 
Csharp :: static {} 
Csharp :: c# bitwise or 
Csharp :: c# xamarin forms use AssetManager to get text file 
Csharp :: unity transform.translate 
Csharp :: unity pause 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =