// By Chris Orban and Mark Schillaci for Physics 1251 at OSU Marion float x; float y; float vx=10.0; float vy; float deltaVx; float deltaVy; float mass = 2.0; // Atomic mass unit float dt = 0.1; float x_plate_left = 200; float x_plate_right = 500; float q = 1; // elementary charge float E = 5; // basically just Newtons per elementary charge // if you think of pixels as meters float B = -0.667; float xinitial; float yinitial; //For drawing the image of the particle PImage img; //For drawing the direction of the magnetic field PImage bfld; void setup() { size(775,500); smooth(); xinitial = 0.05*width; yinitial = height/2; x = xinitial; y = yinitial; img = loadImage("http://www.physics.ohio-state.edu/~orban/physics1251lab/proton.png"); if( B < 0 ){ bfld = loadImage("http://www.physics.ohio-state.edu/~orban/physics1251lab/into_magfield.png"); } else if (B > 0) { bfld = loadImage("http://www.physics.ohio-state.edu/~orban/physics1251lab/oop_magfield.png"); } } // For people with C and C++ experience, draw() is // very similar to main(), except that draw() // is run over and over again void 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; deltaVy = 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 ship and other stuff display(); } // end draw()