HTML
<rect id="red" style="fill: red;" height="100" width="20"></rect>
JS
var layer =
{
sizeReal : { "width": 20, "height": 100 }
, sizeScaled : { "width": 10, "height": 50 }
, position : { "x": 200, "y": 200 }
, scale : 0.5
, rotation : 0
, matrix : [ 1, 0, 0, 1, 0, 0 ]
};
// Not sure if its the cleanest way but it works it rotates itself arounds its center.
//
$("#red")[0].setAttribute( 'transform', 'translate(' + layer.position.x + ',' + layer.position.y +') rotate(' + layer.rotation +',' + ( layer.sizeScaled.width / 2 ) + ',' + ( layer.sizeScaled.height / 2 ) + ') scale(' + layer.scale + ',' + layer.scale +')' )
The example above changes the SVG rectangle by applying a transform. I want to do the same, using a matrix. I’m using Sylvester to multiply the matrixes. I made a fiddle to make the question clear 🙂
I want the red rect to behave the same as the green rect. What am I doing wrong?
Fixed!! the sequence of the matrix elements was wrong 🙂
http://jsfiddle.net/6DR3D/2/