I'm having some problems rotating rectangles on an HTML canvas in their place. As you can see in the JS Fiddle, the original image is shown here: https://jsfiddle.net/vyx2hbky/. What I want to do is rotate the lines slightly, say by like, 45 degrees, in their place.
When I uncomment the commented code in the JS Fiddle, which is this,
ctx.translate(coords[0], coords[1]);
ctx.rotate(Math.PI / 4);
all of the original rectangles go haywire and it looks like a mess. They are not rotating in their own spot, and I'm not really sure how to fix this.
I have looked at previous Stack Overflow questions regarding rotating rectangles in their center point, but I'm not really sure how to find the center point of each individual rectangle to begin with, and how I can replicate this process for every single rectangle in the canvas.
I have tried doing ctx.translate(coords[0] + c.width / 2, coords[1] + c.height / 2)
, as per some previous Stack Overflow answers, but this doesn't seem to work. Any guidance would be appreciated!