C# virtual synthesizer and keyboard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1KB

  1. using System;
  2. using System.Drawing;
  3. namespace NVSynth
  4. {
  5. public class Util
  6. {
  7. public static Color ColorFromHSV(double hue, double saturation, double value)
  8. {
  9. int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
  10. double f = hue / 60 - Math.Floor(hue / 60);
  11. value = value * 255;
  12. int v = Convert.ToInt32(value);
  13. int p = Convert.ToInt32(value * (1 - saturation));
  14. int q = Convert.ToInt32(value * (1 - f * saturation));
  15. int t = Convert.ToInt32(value * (1 - (1 - f) * saturation));
  16. if (hi == 0)
  17. return Color.FromArgb(255, v, t, p);
  18. else if (hi == 1)
  19. return Color.FromArgb(255, q, v, p);
  20. else if (hi == 2)
  21. return Color.FromArgb(255, p, v, t);
  22. else if (hi == 3)
  23. return Color.FromArgb(255, p, q, v);
  24. else if (hi == 4)
  25. return Color.FromArgb(255, t, p, v);
  26. else
  27. return Color.FromArgb(255, v, p, q);
  28. }
  29. }
  30. }