/** @id MochiKit.Color.Color.prototype.colorWithAlpha */
colorWithAlpha: function (alpha) { var rgb = this.rgb; var m = MochiKit.Color; return m.Color.fromRGB(rgb.r, rgb.g, rgb.b, alpha);
},
/** @id MochiKit.Color.Color.prototype.colorWithHue */
colorWithHue: function (hue) { // get an HSL model, and set the new hue... var hsl = this.asHSL();
hsl.h = hue; var m = MochiKit.Color; // convert back to RGB... return m.Color.fromHSL(hsl);
},
/** @id MochiKit.Color.Color.prototype.colorWithSaturation */
colorWithSaturation: function (saturation) { // get an HSL model, and set the new hue... var hsl = this.asHSL();
hsl.s = saturation; var m = MochiKit.Color; // convert back to RGB... return m.Color.fromHSL(hsl);
},
/** @id MochiKit.Color.Color.prototype.colorWithLightness */
colorWithLightness: function (lightness) { // get an HSL model, and set the new hue... var hsl = this.asHSL();
hsl.l = lightness; var m = MochiKit.Color; // convert back to RGB... return m.Color.fromHSL(hsl);
},
/** @id MochiKit.Color.Color.prototype.darkerColorWithLevel */
darkerColorWithLevel: function (level) { var hsl = this.asHSL();
hsl.l = Math.max(hsl.l - level, 0); var m = MochiKit.Color; return m.Color.fromHSL(hsl);
},
/** @id MochiKit.Color.Color.prototype.lighterColorWithLevel */
lighterColorWithLevel: function (level) { var hsl = this.asHSL();
hsl.l = Math.min(hsl.l + level, 1); var m = MochiKit.Color; return m.Color.fromHSL(hsl);
},
/** @id MochiKit.Color.Color.prototype.blendedColor */
blendedColor: function (other, /* optional */ fraction) { if (typeof(fraction) == 'undefined' || fraction === null) {
fraction = 0.5;
} var sf = 1.0 - fraction; var s = this.rgb; var d = other.rgb; var df = fraction; return MochiKit.Color.Color.fromRGB(
(s.r * sf) + (d.r * df),
(s.g * sf) + (d.g * df),
(s.b * sf) + (d.b * df),
(s.a * sf) + (d.a * df)
);
},
/** @id MochiKit.Color.Color.prototype.compareRGB */
compareRGB: function (other) { var a = this.asRGB(); var b = other.asRGB(); return MochiKit.Base.compare(
[a.r, a.g, a.b, a.a],
[b.r, b.g, b.b, b.a]
);
},
MochiKit.Base.update(MochiKit.Color, { /** @id MochiKit.Color.clampColorComponent */
clampColorComponent: function (v, scale) {
v *= scale; if (v < 0) { return 0;
} elseif (v > scale) { return scale;
} else { return v;
}
},
_hslValue: function (n1, n2, hue) { if (hue > 6.0) {
hue -= 6.0;
} elseif (hue < 0.0) {
hue += 6.0;
} var val; if (hue < 1.0) {
val = n1 + (n2 - n1) * hue;
} elseif (hue < 3.0) {
val = n2;
} elseif (hue < 4.0) {
val = n1 + (n2 - n1) * (4.0 - hue);
} else {
val = n1;
} return val;
},
/** @id MochiKit.Color.hsvToRGB */
hsvToRGB: function (hue, saturation, value, alpha) { if (arguments.length == 1) { var hsv = hue;
hue = hsv.h;
saturation = hsv.s;
value = hsv.v;
alpha = hsv.a;
} var red; var green; var blue; if (saturation === 0) {
red = value;
green = value;
blue = value;
} else { var i = Math.floor(hue * 6); var f = (hue * 6) - i; var p = value * (1 - saturation); var q = value * (1 - (saturation * f)); var t = value * (1 - (saturation * (1 - f))); switch (i) { case 1: red = q; green = value; blue = p; break; case 2: red = p; green = value; blue = t; break; case 3: red = p; green = q; blue = value; break; case 4: red = t; green = p; blue = value; break; case 5: red = value; green = p; blue = q; break; case 6: // fall through case 0: red = value; green = t; blue = p; break;
}
} return {
r: red,
g: green,
b: blue,
a: alpha
};
},
/** @id MochiKit.Color.hslToRGB */
hslToRGB: function (hue, saturation, lightness, alpha) { if (arguments.length == 1) { var hsl = hue;
hue = hsl.h;
saturation = hsl.s;
lightness = hsl.l;
alpha = hsl.a;
} var red; var green; var blue; if (saturation === 0) {
red = lightness;
green = lightness;
blue = lightness;
} else { var m2; if (lightness <= 0.5) {
m2 = lightness * (1.0 + saturation);
} else {
m2 = lightness + saturation - (lightness * saturation);
} var m1 = (2.0 * lightness) - m2; var f = MochiKit.Color._hslValue; var h6 = hue * 6.0;
red = f(m1, m2, h6 + 2);
green = f(m1, m2, h6);
blue = f(m1, m2, h6 - 2);
} return {
r: red,
g: green,
b: blue,
a: alpha
};
},
/** @id MochiKit.Color.rgbToHSV */
rgbToHSV: function (red, green, blue, alpha) { if (arguments.length == 1) { var rgb = red;
red = rgb.r;
green = rgb.g;
blue = rgb.b;
alpha = rgb.a;
} var max = Math.max(Math.max(red, green), blue); var min = Math.min(Math.min(red, green), blue); var hue; var saturation; var value = max; if (min == max) {
hue = 0;
saturation = 0;
} else { var delta = (max - min);
saturation = delta / max;
var makeColor = function (name, r, g, b, a) { var rval = this.fromRGB(r, g, b, a); this[name] = function () { return rval; }; return rval;
};
for (var k in colors) { var name = k + "Color"; var bindArgs = m.concat(
[makeColor, this.Color, name],
colors[k]
); this.Color[name] = m.bind.apply(null, bindArgs);
}
var isColor = function () { for (var i = 0; i < arguments.length; i++) { if (!(arguments[i] instanceof Color)) { returnfalse;
}
} returntrue;
};
var compareColor = function (a, b) { return a.compareRGB(b);
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.