The functions ctx.transform , ctx.rotate , ctx.scale and ctx.translate work by creating a new matrix and then multiplying the existing transformation by this new matrix.
This means that the result of using these functions will depend on the current state of the conversion.
To ensure that the transforms are applied to the default matrix (identifier) ββreset the transform matrix with the ctx.setTransform(1, 0, 0, 1, 0, 0) function, which replaces the existing matrix with the new default matrix.
If you do this before each set of transforms, you will not need to use save and restore to maintain the current state of the transform.
source share