Animating two curves with the same x coordinate

I’m doing a project which ideally requires me to animate both of these lines. When i=500, I would like for the cart to go onto the other line m(x) so it is a continuous loop. Not sure how this can be achieved.

Here is a method that uses the ticker and actions. I don’t know if that’s what you are looking for or not. Let me know if you have questions about it.