// Tyler Rigsby, CSE 142 // Does an animation of a ball falling down import java.awt.*; public class BallDemo { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(500, 500); Graphics g = panel.getGraphics(); double ball1X = 150.0; double ball1Y = 50.0; double ball1V0 = 15.0; double ball1A = 40.0; for (double t = 0.0; t <= 20.0; t += .05) { double ball1Loc = ball1Y + displacement(ball1A, ball1V0, t); g.fillOval((int) ball1X, (int) ball1Loc, 30, 30); panel.sleep(50); panel.clear(); } } // Returns the displacement of an object given acceleration a, // initial velocity v0, and time t public static double displacement(double a, double v0, double t) { return 0.5 * a * t * t + v0 * t; } }