Solved: https://twitter.com/arcadio_g_s/status/1003147830163226624 (swapping -cx
and -cy
)
I'm having a geometry problem, and I need help!
For reference, here's the CodePen.
What I'm trying to do:
I want to call drawRect(..)
with a canvas's context, and have it draw a rectangle as its coded to do.
I also want to be able to create another canvas which represents the 90-degree clockwise rotation of the first canvas. This second canvas actually has the reversed dimensions (width is height, height is width). I want to call the same drawRect(..)
with that second canvas, and have it draw the rotated rectangle.
To be clear, I don't want to draw a different rectangle, I want to draw the same rectangle, but I want it to have been rotated in its drawing.
Requirements:
drawRect(..)
cannot be modified- the values of
rectWidth
/rectHeight
cannot be modified - the second canvas actually has to be of the reversed dimensions and the drawing has to have been drawn to it after the rotation
- the rotation has to be programmatic through the canvas API, not through CSS/etc
- Before calling
drawRect(..)
, I need to be able to apply other transformations in addition to the rotation, such as flipping the drawing horizontally (viatranslate(..)
andscale(-1,1)
). In other words, after the rotation, the registration point needs to be back at 0,0 for subsequent transforms (if needed).