Tie the auto-resizing of a window to the window

The interval and timeout involved in auto-resizing a window was spawned
by the original window, not the window they were resizing. The outcome
was that when the child window was closed, the interval was still trying
to resize the window, which resulted in errors in some browsers. Now the
interval and timeout are spawned by the child, and stop when the child
is closed.
Use the number method ^ instead of math.pow

Numbers have an exponent method on them, which is preferable to using
the same method in the math module.
Move to frames instead of constant redraws

Every time an object changed their state, the whole canvas had to be
redrawn. Now a change in state notifies the canvas that it needs to be
redrawn, and the canvas will redraw itself every frame if it has been
notified.