diff options
author | wout <wout@impinc.co.uk> | 2014-01-31 16:22:01 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-01-31 16:22:01 +0100 |
commit | 2b2a4040f69fde2fb6555c663da8ef6235639dd0 (patch) | |
tree | 522edabba7b250ff7fa31011213a98e95786e59e /src/color.js | |
parent | b095d2949b24da056a0d968e0f2ba306d0d1f48d (diff) | |
download | svg.js-2b2a4040f69fde2fb6555c663da8ef6235639dd0.tar.gz svg.js-2b2a4040f69fde2fb6555c663da8ef6235639dd0.zip |
Added morph() and at() methods to SVG.Color
Diffstat (limited to 'src/color.js')
-rwxr-xr-x | src/color.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/color.js b/src/color.js index 57a4d64..9821743 100755 --- a/src/color.js +++ b/src/color.js @@ -60,6 +60,24 @@ SVG.extend(SVG.Color, { + (this.g / 255 * 0.59) + (this.b / 255 * 0.11) } + // Make color morphable +, morph: function(color) { + this.destination = new SVG.Color(color) + + return this + } + // Get morphed color at given position +, at: function(pos) { + /* make sure a destination is defined */ + if (!this.destination) return this + + /* generate morphed array */ + return new SVG.Color({ + r: ~~(this.r + (this.destination.r - this.r) * pos) + , g: ~~(this.g + (this.destination.g - this.g) * pos) + , b: ~~(this.b + (this.destination.b - this.b) * pos) + }) + } // Private: ensure to six-based hex , _fullHex: function(hex) { return hex.length == 4 ? @@ -87,4 +105,11 @@ SVG.Color.test = function(color) { // Test if given value is a rgb object SVG.Color.isRgb = function(color) { return color && typeof color.r == 'number' + && typeof color.g == 'number' + && typeof color.b == 'number' +} + +// Test if given value is a color +SVG.Color.isColor = function(color) { + return SVG.Color.isRgb(color) || SVG.Color.test(color) }
\ No newline at end of file |