I Don't Know How To...

I'm trying to make a sonic game, but I don't know how to get the characters to go through the loop. Can I get some help? Please.
animpos=direction(xprevious,yprevious,x,y);//for 360
angle=direction(xprevious,yprevious,x,y);//for 90
animpos=angle/4;
angle=direction(xprevious,yprevious,x,y);//for 36
animpos=angle/10;