xxxxxxxxxx
57
let dxy;
let dvv;
let dac;
let xy;
let vv;
let acc;
let rr;
const xx = 200;
const yy = 20;
const GM = 200;
function setup() {
createCanvas(400, 400);
xy = createVector(xx, yy);
vv = createVector(0, 0);
acc = createVector(0, 0);
dxy = createVector(12, 12);
dvv = createVector(0, 0);
dac = createVector(0, 0);
}
function draw() {
background(220);
noStroke();
fill(40);
circle(200, 400, 160);
circle(xy.x - dxy.x / 2, xy.y, 4);
circle(xy.x + dxy.x / 2, xy.y, 4);
circle(xy.x, xy.y - dxy.y / 2, 4);
circle(xy.x, xy.y + dxy.y / 2, 4);
stepMotion();
// console.log(vv.y);
if (dxy.x <= 0 || dxy.y <= 0) {
saveGif('tidal', frameCount - 1, {units:"frames"});
noLoop();
}
}
function stepMotion() {
rr = 400 - xy.y;
acc.x = 0;
acc.y = GM / rr ** 2;
dac.x = (-GM * dxy.x) / rr ** 3;
dac.y = (2 * GM * dxy.y) / rr ** 3;
vv.add(acc);
xy.add(vv);
dvv.add(dac);
dxy.add(dvv);
}