import java.awt.*; /** Program: Level29 Purpose: extend custom class + solve d.e. most naively @author: Paul Garrett, garrett@math.umn.edu @version: 29, Thu Feb 20 12:17:45 CST 1997 */ public class Level29 extends TimedApplet1 { int t; float xold, yold, xmed, ymed, xnew, ynew; int theWidth, theHeight; float increment = 1F; final float gravity = 60000F; final float xDotDot(float x, float y) { float rad = (float) Math.sqrt(x*x + y*y); return gravity * ( - x) / (rad * rad * rad); } final float yDotDot(float x, float y) { float rad = (float) Math.sqrt(x*x + y*y); return gravity * ( - y) / (rad * rad * rad); } public void init() { theWidth = this.size().width; theHeight = this.size().height; t = 0; xnew = 100F; ynew = 100F; xmed = 90F; ymed = 110F; } public void run() { while (true) { pause(100); xold = xmed; yold = ymed; xmed = xnew; ymed = ynew; xnew = 2F * xmed - xold + xDotDot(xmed,ymed); ynew = 2F * ymed - yold + yDotDot(xmed,ymed); repaint(); t++; } } public void paint(Graphics g) { g.setColor(Color.yellow); g.fillOval((theWidth/2),(theHeight/2),10,10); g.setColor(Color.black); g.drawLine((theWidth/2) + (int) xmed, (theHeight/2) - (int) ymed, (theWidth/2) + (int) xnew, (theHeight/2) - (int) ynew); } public void update(Graphics g) { paint(g); } } // the end