09-12
This commit is contained in:
@@ -59,23 +59,25 @@ function rgbToHsv([R, G, B]) {
|
||||
B /= 255
|
||||
const max = Math.max(R, G, B)
|
||||
const min = Math.min(R, G, B)
|
||||
const range = max - min
|
||||
let V = max
|
||||
let S = V === 0 ? 0 : range / V
|
||||
let H = 0
|
||||
if (R === V) H = (60 * (G - B)) / range
|
||||
if (G === V) H = 120 + (60 * (B - R)) / range
|
||||
if (B === V) H = 240 + (60 * (R - G)) / range
|
||||
|
||||
if (range === 0) H = 0
|
||||
if (H < 0) H += 360
|
||||
H = (H / 2) * (256 / 180)
|
||||
S *= 255
|
||||
V *= 255
|
||||
|
||||
H = parseInt(H)
|
||||
S = parseInt(S)
|
||||
V = parseInt(V)
|
||||
const delta = max - min
|
||||
var H,S,V
|
||||
if (delta === 0) {
|
||||
H = 0;
|
||||
} else if (max === R) {
|
||||
H = ((G - B) / delta) % 6;
|
||||
} else if (max === G) {
|
||||
H = (B - R) / delta + 2;
|
||||
} else { // max === B
|
||||
H = (R - G) / delta + 4;
|
||||
}
|
||||
H = Math.round(H * 60); // 范围为 0-360
|
||||
if (max === 0) {
|
||||
S = 0;
|
||||
} else {
|
||||
S = delta / max;
|
||||
}
|
||||
S = Math.round(S*100); // 范围为 0-100
|
||||
V = Math.round(max*100); // 范围为 0-100
|
||||
return [H, S, V]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user