// By Chris Orban for Physics 1251 at OSU Marion float x; float y; float vx=10.0; float vy; float deltaVx; float deltaVy; float mass = 1.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; // Natural units //For drawing the image of the proton PImage img; void setup() { size(750,500); smooth(); x = 0.05*width; y = height/2; img = loadImage("http://www.physics.ohio-state.edu/~orban/physics1251lab/proton.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; // Update location x += vx*dt; // Set deltaV to zero (thrust off unless user turns it on) deltaVx = 0; if ( ( x > x_plate_left) & (x < x_plate_right)) { deltaVx = (q*E/mass)*dt; } // Draw ship and other stuff display(); if ( (x > width) | (x < 0) ) { drawText("Final Velocity = ",width/2-125,height/2); drawText(vx,width/2+25,height/2); noLoop(); } } // end draw()