xxxxxxxxxx
57
x = 0;
y = 250;
vx=10.0;
vy=0.0;
deltaVx=0.0;
deltaVy=0.0;
mass = 2.0; // Atomic mass unit
dt = 0.1;
x_plate_left = 200;
x_plate_right = 500;
q = 1; // elementary charge
E = 5; // Natural units
B = -0.9;
// For people with C and C++ experience, draw() is
// very similar to main(), except that draw()
// is run over and over again
function draw() {
// Update velocities
vx += deltaVx;
vy += deltaVy;
// Update location
x += vx*dt;
y += vy*dt;
// Set deltaV to zero (thrust off unless user turns it on)
deltaVx = 0;
deltaVx = 0;
if ( ( x > x_plate_left) && (x < x_plate_right))
{
deltaVx = (q*E/mass)*dt;
}
// If the charge is in the region with the magnetic field
if ( x > x_plate_right )
{
deltaVx = 0.0; // change in vx from magnetic field
deltaVy = 0.0; // change in vy from magnetic field
}
// Draw axes and other stuff
display();
positive(x,y,vx,vy,deltaVx/dt,deltaVy/dt);
} // end draw()