xxxxxxxxxx
44
// proton radius: 0.8414 fm
let scl = 0.02;
let protonRadius = 0.8414; // in fm
let electronMass = 0.9109; // in ap kg
let charge = 0.1602; // in aC
let constant = 8.987; // in Gkgm^3s^-2C^-2
let v = 1; // in fm/frame
let iterations = 10;
function setup() {
createCanvas(640, 360);
}
function draw() {
background(255);
push();
translate(width / 2, height / 4);
fill(255, 0, 0);
stroke(0);
strokeWeight(3);
circle(0, 0, protonRadius / scl * 2);
stroke(255, 255, 0);
noFill();
for (let i = -width / 8; i <= width / 8; i += width / 8 / 5) {
let pos = createVector(i * scl, -height * scl); // in fm
let vel = createVector(0, v); // in fm/s
let acc = createVector(0, 0); // in fm/s^2
beginShape();
for (let steps = 0; steps < 100; steps++) {
for (let it = 0; it < iterations; it++) {
let mag = constant * charge * charge / pos.magSq(); // G * a * a / (f * f) = kN
let force = p5.Vector.mult(p5.Vector.normalize(pos), -mag);
let acc = p5.Vector.div(force, electronMass); // k / (a * p) = EP m/s^2
vel.add(p5.Vector.div(p5.Vector.mult(acc), iterations));
pos.add(vel);
acc.mult(0);
}
vertex(pos.x / scl, -pos.y / scl);
}
endShape();
}
pop();
noLoop();
}