Demo
The sprite moves with W A S D.
It flips by assigning a class='flip', styled in CSS.
The position is read then written-back, to keep the state
as the SVG mark-up.
Javascript is memoryless, handling key
events and calculations, essentially doing svg ~= svg + change*dt