If you refer to the ejs code.
In the code, I calculate r=(x[sup]2[/sup]+y[sup]2[/sup])[sup]1/2[/sup]
,the force was calculated as F=-GMm/r[sup]2[/sup].
When I want to have x-component of the force: I use Fx=F*x/r
Similar for y-component of the force: Fy=F*y/r.
Because  x/r =cos(theta), y/r=sin(theta).