working algorithm for moving figures