Generalization of animation code