xxxxxxxxxx
47
let p1, p2, ob;
const r1 = 50;
const r2 = 100;
const w1 = 0.001;
const w2 = 0.0005;
const m1 = 20;
const m2 = 1;
let t;
function setup() {
createCanvas(400, 400);
t = 0;
p1 = createVector(r1, 0);
p2 = createVector(-r2, 0);
ob = createVector(0, 100);
}
function draw() {
background(220);
p1.x = r1 * cos(w1 * t);
p1.y = r1 * sin(w1 * t);
p2.x = r2 * cos(w2 * t + PI);
p2.y = r2 * sin(w2 * t + PI);
ob = p5.Vector.add(p5.Vector.mult(p1,m1),p5.Vector.mult(p2,m2)).div(m1+m2);
circle(200, 200, 2);
noFill();
stroke(180);
circle(200, 200, 2 * r1);
circle(200, 200, 2 * r2);
translate(ob.x + 200, ob.y + 200);
p1.sub(ob);
p2.sub(ob);
noStroke();
fill(40);
circle(p1.x, p1.y, 5);
circle(p2.x, p2.y, 5);
t += deltaTime;
}
function stepMotion() {}