Guest User

Untitled

a guest
Jan 13th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////////
  2. // Expressions
  3. //////////////////////////////////////////////////////////////////////////////////
  4.  
  5. int clamp(int val,int min,int max)
  6. {
  7.     if (val<min) {return min;}
  8.     if (val>max) {return max;}
  9.     return val;
  10. }
  11. int mod(int val,int max)
  12. {
  13.     return (val%max < 0)? max-(val%max) : val%max ;
  14. }
  15.  
  16. long ExtObject::eHSBtoRGB(LPVAL params, ExpReturn& ret)
  17. {
  18.     float H = mod(params[0].GetInt(),360);
  19.     float S = clamp(params[1].GetInt(),0,100);
  20.     float V = clamp(params[2].GetInt(),0,100);
  21.  
  22.     H /= 60.0;
  23.     S /= 100.0;
  24.     V /= 100.0;
  25.  
  26.     float m,n,f;
  27.     float R,G,B;
  28.     int i;
  29.  
  30.     i = floor(H);
  31.     f = H - i;
  32.     if ( !(i&1) ) f = 1 - f; // if i is even
  33.     m = V * (1 - S);
  34.     n = V * (1 - S * f);
  35.     switch (i) {
  36.     case 6:
  37.     case 0: { R=V; G=n; B=m; break; }
  38.     case 1: { R=n; G=V; B=m; break;}
  39.     case 2: { R=m; G=V; B=n; break;}
  40.     case 3: { R=m; G=n; B=V; break;}
  41.     case 4: { R=n; G=m; B=V; break;}
  42.     case 5: { R=V; G=m; B=n; break;}
  43.     }
  44.     COLORREF c3 = RGB(R*255,G*255,B*255);
  45.     return ret = (int)c3;
  46. }
Add Comment
Please, Sign In to add comment