Ball.javaimport java.awt.*;
import java.util.Random;
public class Ball
{
double px, py;
double vx, vy;
double mass;
int radius;
Color color;
Ball()
{
color = new Color(255,0,0);
px = 50;
py = 60;
vx = 8;
vy = 9;
set_radius(17);
}
Ball(int px, int py, int vx, int vy, Color color)
{
this.px = px;
this.py = py;
this.vx = vx;
this.vy = vy;
this.color = color;
set_radius(17);
}
public void randomize(double v)
{
Random r = new Random();
px = 400*r.nextDouble();
py = 400*r.nextDouble();
double theta = r.nextDouble()*2.0*Math.PI;
vx = v*Math.cos(theta);
vy = v*Math.sin(theta);
}
public void set_radius(int r)
{
radius = r;
mass = r*r;
}
public String toString()
{
String str = "("+px+", "+py+") " + color;
return str;
}
public void move()
{
px += vx;
py += vy;
}
public void move(double delta)
{
px += vx*delta;
py += vy*delta;
}
public void draw(Graphics g)
{
g.setColor(color);
g.fillOval((int)(px-radius), (int) (py-radius), (int)2*radius, (int)2*radius);
}
}
Maintained by John Loomis, updated Mon Nov 11 15:59:50 2013