diff options
| author | Jules Laplace <jules@okfoc.us> | 2013-02-23 20:01:04 -0800 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2013-02-23 20:01:04 -0800 |
| commit | af0a54f6b5738272362bec1a2fb62e09bf719e3b (patch) | |
| tree | 9445544562041196a0c05e5645f79d036b03082d /public/js/color.js | |
| parent | c1ab3ea0daff8c40983893d00160ec4dfb8c0f1f (diff) | |
pull in drawing stuff
Diffstat (limited to 'public/js/color.js')
| -rw-r--r-- | public/js/color.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/public/js/color.js b/public/js/color.js new file mode 100644 index 0000000..dff865c --- /dev/null +++ b/public/js/color.js @@ -0,0 +1,65 @@ +function Color (opt) { + if (opt.length == 3) { + this.r = opt[0]; + this.g = opt[1]; + this.b = opt[2]; + this.a = 1; + } + else if (opt.length == 4) { + this.r = opt[0]; + this.g = opt[1]; + this.b = opt[2]; + this.a = opt[3]; + } +} +Color.prototype.toString = function(){ + return "rgba(" + this.r + "," + this.g + "," + this.b + "," + this.a + ")"; +} +Color.prototype.rgb = function(){ + return [ this.r, this.g, this.b ]; +} +Color.prototype.rgba = function(){ + return [ this.r, this.g, this.b, this.a ]; +} +Color.prototype.hsl = function(){ +} +Color.prototype.copy = function(){ + return new Color( this.rgba() ); +} +Color.prototype.alpha = function(a){ + var c = this.copy() + c.a = a; + return c; +} +Color.prototype.swatch = function(){ + var that = this; + var el = document.createElement("div"); + el.className = "swatch"; + el.style.backgroundColor = this.toString(); + document.getElementById("palette").appendChild(el); + el.onclick = function(){ + color = that; + makeBrushes(); + brush = brush.copy({ color: color }); + } +} + + +var colors = { + red: new Color([ 255,0,0,0.1 ]), + blue: new Color([ 0,0,255 ]), + black: new Color([ 0,0,0 ]), + green: new Color([ 0,128,0 ]), + cyan: new Color([ 0,255,255 ]), + yellow: new Color([ 255,255,0 ]), + peru: new Color([ 205,133,63 ]), +} + +for (var c in colors) { + if (colors.hasOwnProperty(c)) { + colors[c].swatch(); + } +} + +var color = colors.black; + |
