move line animation code into function