// July 2002, java applet by Oliver Knill for the CCP project // Vector Fields and Line Integrals by Oliver Knill and Dale Winter // Harvard University, Nov 15, 2002. See // http://www.math.duke.edu/education/ccp/materials/mvcalc/vfield/index.html // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License of the Free Software Foundation for // details. Compile with // javac pencil.java vectorfield.java lineintegral.java import java.awt.*; class pencil { private int h,w; private int x,y; // pencil location private int i,j; // indices private int wr; // wheel radius private int wf; // number vectors in each dimension private int x_cen,y_cen; // pencil center private int a,b; // new center private int a_old,b_old; private int x_old,y_old; private int pencil_length=15; // pencil length private int left_border=80; // left border for menu public pencil(int width,int height) { this.w = width; this.h = height; wf = 4; wr = (int) w/70; x_cen = w/2; y_cen = h/2; x = x_cen; y = y_cen; a = x+pencil_length; b = y-pencil_length; } public void read_pointer(int x, int y) { this.x = x+4; this.y = y-4; } public void paint(Graphics g) { g.setColor(Color.black); g.fillRect(0,0,w,h); } private void erase_old_pencil(Graphics g) { g.setColor(Color.black ); for (i=-1; i<2; i++) for (j=-1;j<2; j++) { g.drawLine(x_old+i, y_old+j,a_old+2*i, b_old+2*j); } g.drawOval(x_old-wr, y_old-wr, 2*wr, 2*wr); g.fillOval(a_old-wf,b_old-wf,2*wf,2*wf-1); g.drawOval(a_old-wf,b_old-wf,2*wf,2*wf-1); g.drawLine(x_old-4,y_old+4,x_old,y_old); g.drawLine(x_old-3,y_old+2,x_old,y_old+1); g.drawLine(x_old-2,y_old+3,x_old+1,y_old); } private void draw_new_pencil(Graphics g) { g.setColor(new Color(0,0,255)); for (i=-1; i<2; i++) for (j=-1;j<2; j++) { g.drawLine(x+i, y+j, a+2*i, b+2*j); } g.setColor(new Color(0,0,127)); g.fillOval(a-wf,b-wf,2*wf,2*wf-1); g.setColor(new Color(60,60,117)); g.drawOval(a-wf,b-wf,2*wf,2*wf-1); g.setColor(new Color(200,200,255)); g.drawLine(x-4,y+4,x,y); g.drawLine(x-3,y+2,x,y+1); g.drawLine(x-2,y+3,x+1,y); } public void update( Graphics g ) { if (x_old>left_border) { erase_old_pencil(g); } a = (int) (x+pencil_length); b = (int) (y-pencil_length); if (x>left_border) { draw_new_pencil(g); } a_old=a; b_old=b; x_old=x; y_old=y; } }