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/fx.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/fx.js')
-rwxr-xr-x | src/fx.js | 34 |
1 files changed, 9 insertions, 25 deletions
@@ -208,12 +208,17 @@ SVG.extend(SVG.FX, { } // Add animatable attributes , attr: function(a, v, n) { - if (typeof a == 'object') + if (typeof a == 'object') { for (var key in a) this.attr(key, a[key]) - else - this.attrs[a] = { from: this.target.attr(a), to: v } + } else { + var from = this.target.attr(a) + + this.attrs[a] = SVG.Color.isColor(from) ? + new SVG.Color(from).morph(v) : + { from: from, to: v } + } return this } @@ -410,32 +415,11 @@ SVG.extend(SVG.FX, { .plus(new SVG.Number(o.from)) : /* color recalculation */ - o.to && (o.to.r || SVG.Color.test(o.to)) ? - this._color(o, pos) : + o instanceof SVG.Color ? o.at(pos) : /* for all other values wait until pos has reached 1 to return the final value */ pos < 1 ? o.from : o.to } - // Private: tween color -, _color: function(o, pos) { - var from, to - - /* normalise pos */ - pos = pos < 0 ? 0 : pos > 1 ? 1 : pos - - /* convert FROM */ - from = new SVG.Color(o.from) - - /* convert TO hex to rgb */ - to = new SVG.Color(o.to) - - /* tween color and return hex */ - return new SVG.Color({ - r: ~~(from.r + (to.r - from.r) * pos) - , g: ~~(from.g + (to.g - from.g) * pos) - , b: ~~(from.b + (to.b - from.b) * pos) - }).toHex() - } }) |