/*
An object of type MovingBall holds data about a "ball" that has
a color, radius, position, speed, and direction.
The ball is restricted
to moving around inside a rectangle in the xyplane.
The ball can draw
itself in a graphics context and will move when it is told to move.
This class uses some trigonometry and vector math in its implementation.
*/
*
import java.awt.*;
i
public class MovingBall
{
p
private double xmin, xmax;
// The horizontal limits on the ball's position.
//
The xcoordinate of the ball statisfies
//
xmin <= x <= xmax.
private double ymin, ymax;
// The vertical limits on the ball's position.
//
The ycoordinate of the ball statisfies
//
ymin <= y <= ymax.
private double x,y;
// Current position of the ball.
private double dx,dy;
// The velocity (speed + direction) of the ball.
//
When the travel() method is called, the
//
ball moves dx pixesl horizontally and dy
//
pixels vertically.
private Color color;
// The color of the ball.
private double radius;
// The radius of the ball.
public MovingBall(double left, double right, double top, double bottom) {
// Create a ball that moves within the specified limits,
// left <= x <= right and top <= y <= bottom.
The ball is initially
// located in the middle of this range.
It has a random speed
// between 4 and 12 and a random direction.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 jackson
 ball, Unit of time, diameter

Click to edit the document details