This is just a proof of concept. Click on either of the green flags to run the program. The program draws the track and then the wagon automatically follows the rails that have been drawn. I've updated the wagon and the track components The wagon will now turn right and left. You can change the direction the wagon is travelling by pressing T. There will be a delay when the wagon is going round a corner In principle it should work with other track layouts that obey some simple rules. If you click on the little blue rectangle you can see a larger image, but for some reason this doesn't work in my version of Firefox, but it does work in Google Chrome.