웹사이트 관련 팁들을 모아놓은 곳입니다. 좋은팁 공유 합시다.
  • 웹미니 한줄 전광판 영역 입니다.
글 수 186

0

조회 수 : 7221 신고 : 0

작성자 : 웹기프트
포인트 : 17 | 레벨 : 0

출처 : http://snipplr.com/view/14590/hsv-to-rgb/


HSV TO RGB


Published in: JavaScript 


HSV to RGB color conversion. Ported from the excellent java algorithm by Eugene Vishnevsky at: http://www.cs.rit.edu/~ncs/color/t_convert.html.

<pre class="javascript javascript" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1em; padding-right: 0px; padding-bottom: 1em; padding-left: 0px; font: normal normal normal 115%/normal monospace; line-height: 1.22em; font-size: 12px; color: black; font-family: monospace; ">
  1. /**
  2.  * HSV to RGB color conversion
  3.  *
  4.  * H runs from 0 to 360 degrees
  5.  * S and V run from 0 to 100
  6.  *
  7.  * Ported from the excellent java algorithm by Eugene Vishnevsky at:
  8.  * http://www.cs.rit.edu/~ncs/color/t_convert.html
  9.  */
  10. function hsvToRgb(h, s, v) {
  11. var r, g, b;
  12. var i;
  13. var f, p, q, t;
  14.  
  15. // Make sure our arguments stay in-range
  16. = Math.max(0, Math.min(360, h));
  17. = Math.max(0, Math.min(100, s));
  18. = Math.max(0, Math.min(100, v));
  19.  
  20. // We accept saturation and value arguments from 0 to 100 because that's
  21. // how Photoshop represents those values. Internally, however, the
  22. // saturation and value are calculated from a range of 0 to 1. We make
  23. // That conversion here.
  24. /= 100;
  25. /= 100;
  26.  
  27. if(== 0) {
  28. // Achromatic (grey)
  29. = g = b = v;
  30. return [Math.round(* 255), Math.round(* 255), Math.round(* 255)];
  31. }
  32.  
  33. /= 60// sector 0 to 5
  34. = Math.floor(h);
  35. = h - i; // factorial part of h
  36. = v * (1 - s);
  37. = v * (1 - s * f);
  38. = v * (1 - s * (1 - f));
  39.  
  40. switch(i) {
  41. case 0:
  42. = v;
  43. = t;
  44. = p;
  45. break;
  46.  
  47. case 1:
  48. = q;
  49. = v;
  50. = p;
  51. break;
  52.  
  53. case 2:
  54. = p;
  55. = v;
  56. = t;
  57. break;
  58.  
  59. case 3:
  60. = p;
  61. = q;
  62. = v;
  63. break;
  64.  
  65. case 4:
  66. = t;
  67. = p;
  68. = v;
  69. break;
  70.  
  71. default: // case 5:
  72. = v;
  73. = p;
  74. = q;
  75. }
  76.  
  77. return [Math.round(* 255), Math.round(* 255), Math.round(* 255)];
  78. }
</pre>

Report this snippet 

소중한 댓글 부탁드립니다.
추천수 10단위당 메달이 1개씩 노출되고, 추천수에 따라 배경색이 변하며, 일정수의 추천수를 받을시 BEST 아이콘이 붙게됩니다.
추천수에 따른 배경색 보기 본문으로 바로가기
  • 추천수 50개이상
  • 추천수 30개이상
  • 추천수 20개이상
  • 추천수 10개이상
  • 추천수 3개이상
닫기

댓글 '2'

스마일조아 (118187)

2009.11.04 20:03:50

좋은 정보 감사합니다.
열혈개미 (207631)

2010.06.18 19:30:18

감사합니다.

List of Articles
번호 제목 글쓴이 날짜sort 추천 수 조회 수
166 best of best 홈페이지,제로보드 성공담 [12] title: [ani]깜빡이는 표정빽짱구 2004-02-09 27 4880
165 로그인이 안될때~ [2] title: [ani]깜빡이는 표정빽짱구 2004-02-09 11 2776
164 윈도우 단축키 [2] title: [ani]깜빡이는 표정빽짱구 2004-02-10 15 2638
163 저작권 안내 [2] title: [ani]깜빡이는 표정빽짱구 2004-02-11 10 2471
162 best of best 최근게시물 설치 [3] title: [ani]깜빡이는 표정빽짱구 2004-02-12 25 2477
161 best of best html과 tag의 개념 [2] title: [ani]깜빡이는 표정빽짱구 2004-02-17 23 2557
160 폭탄태그 [2] title: [ani]깜빡이는 표정빽짱구 2004-02-17 12 4099
159 링크태그 [2] title: [ani]깜빡이는 표정빽짱구 2004-02-17 13 2468
158 best of best 태그목록 [2] title: [ani]깜빡이는 표정빽짱구 2004-02-17 29 2569
157 마우스 커서모양 바꾸기 [4] title: [ani]깜빡이는 표정빽짱구 2004-02-17 14 3697
156 홈페이지나 까페에 뉴스소식 달기 아이프레임 이용. [2] title: [ani]깜빡이는 표정빽짱구 2004-02-17 18 2913
155 best of best HTML 테그표입니다. [2] title: [ani]깜빡이는 표정빽짱구 2004-02-17 38 3069
154 best of best 무료 도매인 포워딩 사이트 (100개) [1] title: [ani]깜빡이는 표정빽짱구 2004-02-19 27 3029
153 투명& 불투명 iframe 만들기 [1] title: [ani]깜빡이는 표정빽짱구 2004-02-22 12 3426
152 best of best 이미지 & 파일 무단링크 막기 [1] title: [ani]깜빡이는 표정빽짱구 2004-02-22 28 2971
151 best of best font 의 속성 [1] title: [ani]깜빡이는 표정빽짱구 2004-02-22 28 2262
150 절대경로와 상대경로 [1] title: [ani]깜빡이는 표정빽짱구 2004-02-22 18 3450
149 입력란에 한글만 입력되게 하기. [2] title: [ani]깜빡이는 표정빽짱구 2004-02-22 16 3263
148 성인인증 스크립트 [2] title: [ani]깜빡이는 표정빽짱구 2004-02-22 12 3514
147 저장영역 복사및 클립보드로 복사하기 [1] title: [ani]깜빡이는 표정빽짱구 2004-02-22 15 3451