/* * fbwl.java - revised 9 Jan 08 - width 501, height 361 * @author jackord@kw.igs.net * particle sliding in a bowl with friction */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class fbwl extends Applet implements ActionListener { int kk=0; // Declarations double gr, u, s, r; String bs="Plot"; Button b=new Button(bs); public void init() { setLayout(new FlowLayout(FlowLayout.LEFT)); setBackground(new Color(211, 211, 211)); // Light Gray Background add(b); b.addActionListener(this); } public void pin(Graphics g) { // Initialize the Graph g.setFont(new Font("TimesRoman", Font.PLAIN, 16)); g.setColor(Color.black); g.drawRect(88, 12, 400, 300); g.drawLine(88, 162, 488, 162); g.drawString("0", 85, 332); g.drawString("20", 481, 332); g.drawString("Time", 268, 344); g.drawString("-90", 64, 318); g.drawString("0", 72, 168); g.drawString("90", 68, 18); g.drawString("Theta", 16, 93); g.drawString("deg", 24, 243); } double acc(double v) { // Newton's Law return -gr*Math.sin(s/r)+u*(gr*Math.cos(s/r)+v*v/r); } public void paint(Graphics g) { int x1, y1, x2, y2, rr, cc, del; double dt, pi, t, v, dv, vo, theta; String z; pin(g); if (kk==1) { gr=9.8; r=10; u=.12; dt=.02; rr=220; cc=300; z="turns"; t=0; s=r*Math.PI/2; v=0; g.setColor(Color.blue); x1=88; y1=12; long tt=System.currentTimeMillis(); del=5; dv=-gr*dt; v=v+dv/2; vo=v; // Feynman half-step do { t=t+dt; s=s+v*dt; dv=acc(v+dv/2)*dt; v=v+dv; theta=s/r*180/Math.PI; x2=88+(int)(20*t); y2=12+(int)(5*(90-theta)/3); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; if (vo*v<0) { if (Math.abs(u/Math.tan(s/r))>1) { z="stops"; } g.drawString(z+" at theta = "+(float)theta, cc, rr); rr=rr+20; u=-u; } vo=v; tt=tt+del; while (tt>System.currentTimeMillis()) { } } while ((z=="turns")&&(kk>0)); } kk=0; } public void actionPerformed (ActionEvent e) { // Button String tst; tst=e.getActionCommand(); if (bs.equals(tst)) { kk=1; repaint(); } } }