// By Chris Orban for Physics 1251 at OSU Marion float x; float y; float vx=50.0; float vy; float deltaVx; float deltaVy; float mass = 1.0; // Atomic mass unit float dt = 0.05; float x_target = 500; float y_target; float q = 1; // elementary charge float E; // Natural units float qtarget = 1; // elementary charge (atomic number) float k = 100000; // for simplicity, real experiments would use 9e9 float rmin = 10000; //some large number float ri; boolean firsttime = true; //For drawing the image of the proton PImage img; void setup() { size(750,500); smooth(); x = 0.05*width; y = height/2; y_target = y; 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 deltaVx = 0; //float r = ???; // fix this!! if (x < x_target) { E = 0; // fix this!! } else if (x > x_target) { E = 0; // fix this!! } deltaVx = (q*E/mass)*dt; // Draw ship and other stuff display(); drawText("Minimum distance = ",width/2-125,height/2-100); if (rmin > r) rmin = r; drawText(rmin,width/2+100,height/2-100); drawText("Initial distance = ",width/2-125,height/2-150); if (firsttime) { ri = r; firsttime = false; } drawText(ri,width/2+100,height/2-150); if ((x > width) | (x < 0) ) { noLoop(); } } // end draw()