웹사이트 관련 팁들을 모아놓은 곳입니다. 좋은팁 공유 합시다.
글 수 186
0
조회 수 : 7223 신고 : 0
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; ">
- /**
- * HSV to RGB color conversion
- *
- * H runs from 0 to 360 degrees
- * S and V run from 0 to 100
- *
- * Ported from the excellent java algorithm by Eugene Vishnevsky at:
- * http://www.cs.rit.edu/~ncs/color/t_convert.html
- */
- function hsvToRgb(h, s, v) {
- var r, g, b;
- var i;
- var f, p, q, t;
- // Make sure our arguments stay in-range
- h = Math.max(0, Math.min(360, h));
- s = Math.max(0, Math.min(100, s));
- v = Math.max(0, Math.min(100, v));
- // We accept saturation and value arguments from 0 to 100 because that's
- // how Photoshop represents those values. Internally, however, the
- // saturation and value are calculated from a range of 0 to 1. We make
- // That conversion here.
- s /= 100;
- v /= 100;
- if(s == 0) {
- // Achromatic (grey)
- r = g = b = v;
- return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
- }
- h /= 60; // sector 0 to 5
- i = Math.floor(h);
- f = h - i; // factorial part of h
- p = v * (1 - s);
- q = v * (1 - s * f);
- t = v * (1 - s * (1 - 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: // case 5:
- r = v;
- g = p;
- b = q;
- }
- return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
- }
소중한 댓글 부탁드립니다.
추천수 10단위당 메달이 1개씩 노출되고, 추천수에 따라 배경색이 변하며, 일정수의 추천수를 받을시 아이콘이 붙게됩니다.
추천수 10단위당 메달이 1개씩 노출되고, 추천수에 따라 배경색이 변하며, 일정수의 추천수를 받을시 아이콘이 붙게됩니다.
추천수에 따른 배경색 보기
본문으로 바로가기
- 추천수 50개이상
- 추천수 30개이상
- 추천수 20개이상
- 추천수 10개이상
- 추천수 3개이상