1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-12-26 01:13:41 +02:00

Fixed divide by zero issue

This commit is contained in:
Dan Leech 2015-10-16 15:43:13 +01:00
parent f1662ea440
commit d8eee12f69

View File

@ -16,14 +16,15 @@ for (var i = 0; i < source.icons.length; i++) {
var min = Math.min(red, green, blue); var min = Math.min(red, green, blue);
var delta = max - min; var delta = max - min;
source.icons[i].luminance = 100 * (max + min) / 2; source.icons[i].luminance = 100 * (max + min) / 2;
if (delta === 0) {
var hue = 0;
source.icons[i].saturation = 0;
} else {
if (source.icons[i].luminance < 50) { if (source.icons[i].luminance < 50) {
source.icons[i].saturation = 100 * (max - min) / (max + min); source.icons[i].saturation = 100 * (max - min) / (max + min);
} else { } else {
source.icons[i].saturation = 100 * (max - min) / (2 - max - min); source.icons[i].saturation = 100 * (max - min) / (2 - max - min);
} }
if (delta === 0) {
var hue = 0;
} else {
if (max === red) { if (max === red) {
var hue = ((green - blue) / delta) * 60; var hue = ((green - blue) / delta) * 60;
if (hue < 0) { if (hue < 0) {