genearlize animation code