Save and Restore
Learn of the save and restore methods in Pycairo.
We'll cover the following
In one of the previous lessons, we learned to apply several transforms. But how do we remove the transforms, after we are done using them?
Reverse a transformation
It is possible to reverse a transform, by applying the inverse transform. For example, if we apply a translation (a, b)
, we can reverse it by applying a second translation (-a, -b)
, which puts us back where we started. We can reverse a scaling factor s
, by applying a second scaling factor of 1/s
. We can also reverse a rotation through an angle a
by rotating through angle -a
.
However, we often need to apply two transformations: translate
and rotate
. These must be removed in the reverse order;inverse rotate
, followed by inverse translate
. This gets tedious and, often, leads to fragile code.
Get hands-on with 1300+ tech skills courses.