I actually have a file for that! Its designed to work with a physical controller, but the code translates quite readily. Its a bit messy, but I highlighted the important parts in the image.
Ignore the ugly background. It turns out the texture brought the file up over the 2 meg limit.
Basically, the function you need is Angle. It takes 2 points, so if you're making a touch joystick take the origin of the joystick as point 1, and the location of the touch as point 2. angle(JoyOriginx,JoyOriginY,TouchX,TouchY) .