I'm learning Javascript / Raphael and got stuck in what should be something really simple to solve. I need to move and rotate a number of figures with the mouse, but when I rotate them (with doubleclick) as:
rect1.dblclick(function() {
this.rotate('90');
});
the reference points I am using to keep track of the mouse also get rotated. In Processing I would use pushMatrix() and popMatrix(), but I can't find something similar for Raphael nor any simple examples using save() and restore() canvas (...not sure if they can be used here either).
Here is a working example.
var canvas = document.getElementById("the_canvas");
var paper = Raphael(canvas, '500', '500');
var rect1 = paper.rect(380,10,100,50).attr({fill: '#ddd', 'stroke': 'none', opacity: '0.8'});
var startX, startY;
function onstart() {
startX = this.attr('x');
startY = this.attr('y');
}
function onend() {
}
function onmove(dx, dy) {
this.attr({
x: startX + dx,
y: startY + dy
});
}
rect1.drag(onmove, onstart, onend);
//// ... problem here
rect1.dblclick(function() {
this.rotate('90');
});
Cheers,