p5.js, you can find it here: https://editor.p5js.org/christofferaakre/sketches/ZVfm6cPR
if i place two objects with certain masses into the simulation with no initial speeds, then as expected they accelerate towards each other. Something weird happens at the end, but that is just because i haven't told the simulation to anything if they get too close, so as the distance between the two objects get very small the accelerations blow up. When I give one of the objects an initial velocity perpendiculor to the distance between them, I get an elliptical orbit as expected. However, I am having trouble getting binary stars to work. Most of the time, I get something that looks two elliptical orbits about a common centre of mass, as expected, but each consecutive orbit is shifted down by a constant amount. See the image below.
I got the above image when i tried two objects with different masses and equal but opposite velocities. At first I though maybe this could be explained by the binary star system 'moving through space', since the relative positions of the stars are indeed two ellipcital orbits, but relative to the space around them they are also moving downwards.
In this picture, only the object represented by the green trajectory had an initial velocity. Somehow the fact that it had no initial velocity means it only does half an ellipse?? Indeed, if I give if even just a small velocity in the opposite direction, it does complete an orbit:
I'm hoping someone here has a clue as to what is going on here.