summaryrefslogtreecommitdiffstats
path: root/src/fx.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-01-31 16:22:01 +0100
committerwout <wout@impinc.co.uk>2014-01-31 16:22:01 +0100
commit2b2a4040f69fde2fb6555c663da8ef6235639dd0 (patch)
tree522edabba7b250ff7fa31011213a98e95786e59e /src/fx.js
parentb095d2949b24da056a0d968e0f2ba306d0d1f48d (diff)
downloadsvg.js-2b2a4040f69fde2fb6555c663da8ef6235639dd0.tar.gz
svg.js-2b2a4040f69fde2fb6555c663da8ef6235639dd0.zip
Added morph() and at() methods to SVG.Color
Diffstat (limited to 'src/fx.js')
-rwxr-xr-xsrc/fx.js34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/fx.js b/src/fx.js
index 0f73a10..28d0da8 100755
--- a/src/fx.js
+++ b/src/fx.js
@@ -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()
- }
})