Created
October 9, 2012 03:01
-
-
Save mhemesath/3856324 to your computer and use it in GitHub Desktop.
Converts a SVG transform string into a Raphael Matrix object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toMatrix(transform) { | |
var transforms = transform.split(' '), | |
matrix = Raphael.matrix(); | |
for (var i=0; i<transforms.length; i++) { | |
var match = /^(\w+)\((.+)\)$/.exec(transforms[i]), | |
tranform = match[1], | |
values = toFloatArray(match[2]); | |
if ('translate' === transform) matrix.translate.apply(matrix, values); | |
if ('rotate' === transform) matrix.rotate.apply(matrix, values); | |
if ('scale' === transform) matrix.scale.apply(matrix, values); | |
} | |
function toFloatArray() { | |
var values = vals.split(','), | |
numbers = []; | |
for (var i=0; i<values.length; i++) { | |
numbers.push(parseFloat(values[i], 10)); | |
} | |
return numbers; | |
} | |
return matrix; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ah ha! I just realized that the regex's we need are within the raphael source code: https://github.com/DmitryBaranovskiy/raphael/blob/master/raphael.core.js#L228
I'm going to see how far these get me.