make Ox.rgb always return integers

This commit is contained in:
rolux 2012-06-24 17:41:27 +02:00
parent fa84921333
commit d29bc5569b
4 changed files with 9 additions and 25 deletions

View file

@ -29,21 +29,13 @@ Ox.Theme = (function() {
function renderElement(value, type) { function renderElement(value, type) {
var $element, background, color, lightness = that[getTheme()].lightness; var $element, background, color, lightness = that[getTheme()].lightness;
if (type == 'hue') { if (type == 'hue') {
background = Ox.rgb(value, 1, lightness.background).map(function(value) { background = Ox.rgb(value, 1, lightness.background);
return Math.round(value); color = Ox.rgb(value, 1, lightness.color);
});
color = Ox.rgb(value, 1, lightness.color).map(function(value) {
return Math.round(value);
});
} else if (type == 'saturation') { } else if (type == 'saturation') {
background = Ox.range(7).map(function(i) { background = Ox.range(7).map(function(i) {
return Ox.rgb(i * 60, value, lightness.background).map(function(value) { return Ox.rgb(i * 60, value, lightness.background);
return Math.round(value);
});
});
color = Ox.rgb(0, 0, lightness.color).map(function(value) {
return Math.round(value);
}); });
color = Ox.rgb(0, 0, lightness.color);
} else if (type == 'lightness') { } else if (type == 'lightness') {
background = Ox.range(3).map(function() { background = Ox.range(3).map(function() {
return Math.round(value * 255); return Math.round(value * 255);
@ -54,12 +46,10 @@ Ox.Theme = (function() {
} else if (type == 'gradient') { } else if (type == 'gradient') {
background = Ox.range(2).map(function(i) { background = Ox.range(2).map(function(i) {
return Ox.rgb(value, 1, lightness.background).map(function(value) { return Ox.rgb(value, 1, lightness.background).map(function(value) {
return Math.round(value + (i == 0 ? 16 : -16)); return value + (i == 0 ? 16 : -16);
}); });
}); });
color = Ox.rgb(value, 1, lightness.color).map(function(value) { color = Ox.rgb(value, 1, lightness.color);
return Math.round(value);
});
} }
$element = $('<div>') $element = $('<div>')
.addClass( .addClass(

View file

@ -80,9 +80,7 @@ Ox.ColorInput = function(options, self) {
function getRGB() { function getRGB() {
return self.options.mode == 'rgb' return self.options.mode == 'rgb'
? self.options.value ? self.options.value
: Ox.rgb(self.options.value).map(function(value) { : Ox.rgb(self.options.value);
return Math.round(value);
});
} }
return that; return that;

View file

@ -109,11 +109,7 @@ Ox.ColorPicker = function(options, self) {
} }
function getRGB(values) { function getRGB(values) {
return self.options.mode == 'rgb' return self.options.mode == 'rgb' ? values : Ox.rgb(values);
? values
: Ox.rgb(values).map(function(value) {
return Math.round(value);
});
} }
return that; return that;

View file

@ -97,7 +97,7 @@ Ox.rgb = function(hsl) {
}); });
} }
return rgb.map(function(value) { return rgb.map(function(value) {
return value * 255; return Math.round(value * 255);
}); });
}; };