Minor clean-ups.

This commit is contained in:
Jürg Lehni 2011-03-09 13:31:40 +00:00
parent eacf346aab
commit 9fd0381b82
5 changed files with 19 additions and 15 deletions

View file

@ -63,7 +63,7 @@ var Color = this.Color = Base.extend(new function() {
lightgrey: 'd3d3d3', silver: 'c0c0c0', darkgray: 'a9a9a9',
gray: '808080', dimgray: '696969', black: '000000'
};
function hexToRGB(hex) {
hex = hex.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
if (hex.length >= 4) {
@ -76,7 +76,7 @@ var Color = this.Color = Base.extend(new function() {
return rgb;
}
}
function stringToRGB(string) {
if (string.match(/^#[0-9a-f]{3,6}$/i)) {
return hexToRGB(string);
@ -88,7 +88,7 @@ var Color = this.Color = Base.extend(new function() {
return hexToRGB(hex);
}
};
return {
beans: true,
@ -288,7 +288,7 @@ var Color = this.Color = Base.extend(new function() {
components.push(color._alpha);
return HSBColor.read(components);
},
'rgb-gray': function(color) {
// Using the standard NTSC conversion formula that is used for
// calculating the effective luminance of an RGB color:
@ -300,24 +300,24 @@ var Color = this.Color = Base.extend(new function() {
color._alpha
);
},
'hsb-rgb': function(color) {
var components = hsbToRgb(color._hue, color._saturation,
color._brightness);
components.push(color._alpha);
return RGBColor.read(components);
},
'hsb-gray': function(color) {
var rgbColor = converters['hsb-rgb'](color);
return converters['rgb-gray'](rgbColor);
},
'gray-rgb': function(color) {
var component = 1 - color.getGray();
return new RGBColor(component, component, component);
},
'gray-hsb': function(color) {
return new HSBColor(0, 0, 1 - color.getGray());
}
@ -351,4 +351,4 @@ var Color = this.Color = Base.extend(new function() {
};
}, this);
}, { beans: true });
});
});

View file

@ -84,3 +84,4 @@ var GradientColor = this.GradientColor = Color.extend({
return gradient;
}
});

View file

@ -33,4 +33,4 @@ var GrayColor = this.GrayColor = Color.extend({
this._gray = gray;
return this;
}
});
});

View file

@ -32,7 +32,8 @@ var HSBColor = this.HSBColor = Color.extend(new function() {
};
}
}
}, { beans: true,
}, {
beans: true,
_colorType: 'hsb',
_components: components,
@ -44,4 +45,4 @@ var HSBColor = this.HSBColor = Color.extend(new function() {
return this;
}
});
});
});

View file

@ -29,7 +29,9 @@ var RGBColor = this.RGBColor = Color.extend(new function() {
return this;
};
}
}, { beans: true,
}, {
beans: true,
_colorType: 'rgb',
_components: components});
});
_components: components
});
});