E
. . .. . .    .. . .
Peter Müller, Web developer @onecom
A little domain knowledge
#123456
rgb (100, 100, 100)
rgba(100, 100, 100, 0.5)
hsl (100, 100, 100)
hsla(100, 100, 100, 0.5)
"#000000"
[0, 0, 0]
{ R: 0, G: 0, B: 0 }
{ space: 'rgb', R: 0, G: 0, B: 0 }
fromHexToRGB()
fromRGBToHex()
fromHexToHSV()
fromRGBToHSV()
fromHSVToHex()
fromHSVToRGB()
fromHexToHSL()
fromRGBToHSL()
fromHSVToHSL()
fromHSLToHex()
fromHSLToRGB()
fromHSLToHSV()
Color math: [0;1]
... but take a look at https://github.com/harthur/color, lots of good ideas!
one.color = { // General namespace for One.com libs color = function( one.color.* | Array | String | Int ), // Parser }; one.color.installColorSpace: function ( str space, [str channelNames], obj methods ) one.color.installColorSpace("RGB", "Red", "Green", "Blue", "Alpha", {...});
one.color.RGB = function ( [0;1], [0;1], [0;1], [0;1] ) // Constructor
And with plugins:
one.color.HSV = function ( [0;1], [0;1], [0;1], [0;1] ) // Constructor
one.color.HSL = function ( [0;1], [0;1], [0;1], [0;1] ) // Constructor
one.color.CMYK = function ( [0;1], [0;1], [0;1], [0;1] ) // Constructor
Metaprogramming FTW!
Methods added to all installed one.color.* prototypes:
toString() → "[one.color.RGB: Red=0 Green=0 Blue=0 Alpha=1]"
hex() → "#RRGGBB"
css() → "rgb([0;255], [0;255], [0;255])"
cssa() → "rgb([0;255], [0;255], [0;255], [0;1])"
toJSON() → ["RGB", [0;1], [0;1], [0;1], [0;1]]
equals(otherColor, ε = 10-9) → Boolean
[colorSpace] → one.color[colorSpace]
[channelName] → Number [0;1]
[channelName]([0;1]) → new one.color[colorSpace], channelName = [0;1]
[channelName](±[0;1], true) → new one.color[colorSpace], channelName ±= [0;1]
How to write a colorSpace plugin
one.color.installColorSpace('HSV', ['Hue', 'Saturation', 'Value', 'Alpha'], { fromRgb: function () { // Becomes one.color.RGB.prototype.toHSV // SNIP! Colormath is boring, lets go shopping! return new one.color.HSV(h, s, v, this.alpha); }, rgb: function () { // SNIP! Colormath... Go read wikipedia return new one.color.RGB(r, g, b, this.alpha); }, hsl: function () { // SNIP! Colormath... Just copy/paste from someone else return new one.color.HSL(this.h, s, l, this.alpha); } });
Color space conversions
one.color("#99FFFF") .hsv() .hsl() .cmyk() .hex(); → "#99FFFF"
Conversions are implicit, why bother...
Channel manipulation methods
one.color("#99FFFF") .red(0.5) .hue(-0.2, true) .magenta(0) .hex(); → "#99ff80"
Based on the rewritten API version on the 'newapi' branch
The CSS NYAN CAT was created by Michal Budzynski for Mozilla Demo Party in Helsinki June 2011
Sound was disabled for the audiences/visitors pleasure...