// Zorah Fung, CSE 142 // Creates an animation of a ball falling from gravity import java.awt.*; public class BallDemo { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(400, 600); Graphics g = panel.getGraphics(); int ballX = 100; int ballY = 0; int v0 = 25; g.setColor(Color.RED); for (double t = 0; t < 10; t+= 0.05) { double dis = displacement(v0, 9.81, t); g.fillOval(ballX, ballY + (int) dis, 50, 50); panel.sleep(50); panel.clear(); } } // Given an initial velocity and acceleration an object, returns the displacement // the object at time t public static double displacement(double v0, double a, double t) { return v0 * t + 0.5 * a * t * t; } }