21-bouncing-ball

21-bouncing-ball - Mehran Sahami CS 106A Handout #21...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Mehran Sahami Handout #21 CS 106A October 12, 2009 Bouncing Ball Example Based on a handout by Patrick Young. /* * File: BouncingBall.java * ----------------------- * This program graphically simulates a bouncing ball. */ import acm.program.*; import acm.graphics.*; public class BouncingBall extends GraphicsProgram { /** Size (diameter) of the ball */ private static final int DIAM_BALL = 30; /** Amount Y velocity is increased each cycle as a * result of gravity */ private static final double GRAVITY = 3; /** Animation delay or pause time between ball moves */ private static final int DELAY = 50; /** Initial X and Y location of ball */ private static final double X_START = DIAM_BALL / 2; private static final double Y_START = 100; /** X Velocity */ private static final double X_VEL = 5; /** Amount Y Velocity is reduced when it bounces */ private static final double BOUNCE_REDUCE = 0.9; /** Starting X and Y Velocties */ private double xVel = X_VEL; private double yVel = 0.0; /* private instance variable */
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/01/2009 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Page1 / 2

21-bouncing-ball - Mehran Sahami CS 106A Handout #21...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online