Why does my binary star simulation only work for equal masses and initial speeds? I made a 2D gravity simulation is JavaScript using something called 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.
However, I think there is some other issue with my code, because if I only give one of the stars an initial velocity, this happens: 
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. 
 A: It simply looks like your initial condition causes the system to move through space. You need to work in the centre of mass frame. Set
$$m_1v_1=-m_2v_2$$
A: The fact you get good behaviour with equal masses might suggest you are implementing the two-body solution incorrectly.
You can find the common centre of mass by weight ratios but the "reduced mass" for calculating the imaginary body at this point (to make this into 2 single body equations) is not as simple as just using the reduced mass equation found on wiki. (I found this rather strange)
I use the following for the doing two body calculations (in javascript)
    var m1 = body1.mass; 
    var m2 = body2.mass;
    var m3 = m1+m2;
    var mr = Math.pow(m2,3)/Math.pow(m3,2); //reduced mass

Then the gravity acceleration is defined by the reduced mass (mr) and the distance from the centre of mass (for body1)
    var g = GRAVITATIONAL_CONSTANT * mr / Math.pow( r, 2 );

If you don't use the above two body solution your calculations are affected by the time based change in the gravity field at any given point, the reduced mass equations give you a frame and method to describe the gravitational field as fixed and with an inverse square relationship from the centre of mass. When the masses are equal, it is likely your 'reduced mass' method coincides with this (I had this experience)
Yes, this is a reduced mass equation that looks different to the text-book definition, but I found that this is what worked for me when I was doing two body modelling on the path to multiple body models. It looks strange, but sketch it on paper and derive it yourself - it does work!
I am not saying the text-books are wrong, the usual equation is symmetric for both bodies - it is just it is very unclear how it is meant to be implemented.
