MovingBall - /* An object of type MovingBall holds data...

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

View Full Document Right Arrow Icon
/* 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 xy-plane. 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 x-coordinate of the ball statisfies // xmin <= x <= xmax. private double ymin, ymax; // The vertical limits on the ball's position. // The y-coordinate 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. Its radius is 5
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 01/15/2010 for the course CSC 115 taught by Professor Jackson during the Spring '09 term at University of Victoria.

Page1 / 4

MovingBall - /* An object of type MovingBall holds data...

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