/**
* Paints a triangle to represent this Bug.
*
* @param g Where to paint this Bug.
*/
public void paint(Graphics g) {
if (color == null) return;
g.setColor(color);
int x1 = (int) (scaleX(x) + computeDeltaX(12, (int)angle));
int x2 = (int) (scaleX(x) + computeDeltaX(6, (int)angle  135));
int x3 = (int) (scaleX(x) + computeDeltaX(6, (int)angle + 135));
int y1 = (int) (scaleY(y) + computeDeltaY(12, (int)angle));
int y2 = (int) (scaleY(y) + computeDeltaY(6, (int)angle  135));
int y3 = (int) (scaleY(y) + computeDeltaY(6, (int)angle + 135));
g.fillPolygon(new int[] { x1, x2, x3 }, new int[] { y1, y2, y3 }, 3);
}
/**
* Computes how much to move to add to this Bug's xcoordinate,
* in order to displace the Bug by "distance" pixels in
* direction "degrees".
*
* @param distance The distance to move.
* @param degrees The direction in which to move.
* @return The amount to be added to the xcoordinate.
*/
private static double computeDeltaX(int distance, int degrees) {
double radians = Math.toRadians(degrees);
return distance * Math.cos(radians);
}
/**
* Computes how much to move to add to this Bug's ycoordinate,
* in order to displace the Bug by "distance" pixels in
* direction "degrees.
*
* @param distance The distance to move.
* @param degrees The direction in which to move.
* @return The amount to be added to the ycoordinate.
*/
private static double computeDeltaY(int distance, int degrees) {
double radians = Math.toRadians(degrees);
return distance * Math.sin(radians);
}
