Canvas save() and restore()
When working with the canvas element you can save and restore matrix transformations using the save() and restore() methods. These methods are similar to glPushMatrix() and glPopMatrix() from OpenGL – and pushMatrix()/popMatrix() from Processing. Something interesting about save() and restore() is that they also store things like fillStyle, lineWidth, strokeStyle and shadowColor… When working with save() and restore() it’s important to note that your working with a stack data structure. If you don’t know what that is, check out the wikipedia entry. Here’s a demo: