HSV Color value to RGB Color value - CSharp System.Drawing

CSharp examples for System.Drawing:Color RGB

Description

HSV Color value to RGB Color value

Demo Code


using System.Collections.Generic;
using System.Collections;
using UnityEngine;

public class Main{
        public static void HSVtoRGB(out float r, out float g, out float b, float h, float s, float v) {
         int i;
         float f, p, q, t;

         if (s == 0f) {
            r = g = b = v;//from w  ww .jav  a  2  s .c  om
            return;
         }

         h /= 60f;
         i = Mathf.FloorToInt(h);
         f = h - i;
         p = v * (1f - s);
         q = v * (1f - s * f);
         t = v * (1f - s * (1f - f));

         switch (i) {
            case 0: r = v; g = t; b = p; break;
            case 1: r = q; g = v; b = p; break;
            case 2: r = p; g = v; b = t; break;
            case 3: r = p; g = q; b = v; break;
            case 4: r = t; g = p; b = v; break;
            default: r = v; g = p; b = q; break;
         }
      }
}

Related Tutorials