Advertisement
probiner

Houdini VEX hextorgb

May 26th, 2020
1,714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. function float hexchartodec(string char){
  2.     int dec =find("0123456789abcdef", tolower(char))  ;
  3.     if (dec<0) error("invalid hex character: " + char) ;    
  4.     return dec ;
  5. }
  6. function float hextodec(string hex){
  7.     float result = 0;
  8.     foreach(int i; string char; hex) result += hexchartodec(char) * pow(16, i) ;
  9.     return result ;
  10. }
  11.  
  12. function vector hextorgb(string rgbhex){
  13.     if(len(rgbhex)==3) return set(
  14.             hextodec(rgbhex[0]+rgbhex[0]),
  15.             hextodec(rgbhex[1]+rgbhex[1]),
  16.             hextodec(rgbhex[2]+rgbhex[2])) / 255.0 ;
  17.     else return set(
  18.             hextodec(reverse(rgbhex[0:2])),
  19.             hextodec(reverse(rgbhex[2:4])),
  20.             hextodec(reverse(rgbhex[4:6]))) / 255.0 ;
  21. }
  22.  
  23. //test
  24. @Cd = hextorgb("f50") ;
  25. @Cd = hextorgb("AF15B0") ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement