As also noted in this article, the order of transformations is important.
- Move the object so that the center point (or any other point you want to rotate) is at 0,0
- Rotate
- Translate previous position
Also note that there is a rotate overload that already does this.
<html> <head> <script type="text/javascript" src="http://github.com/DmitryBaranovskiy/raphael/blob/master/raphael-min.js?raw=true"></script> <script type="text/javascript"> function Draw() { var x = 150, y = 150; var rotation = 0; var paper = Raphael(0, 0, 800, 800); var e = paper.ellipse(x, y, 30, 10); paper.path("M150 150L800 150"); window.setInterval(function() { x += 10; rotation += 10; e.translate(10, 0); e.rotate(rotation, x, y); }, 500); } </script> </head> <body onload="Draw()"> </body> </html>
source share