package graphics.radar;
import graphics.ImageUtils;
import java.awt.*;
public class Radar extends java.awt.Canvas {
private double thetaInRadians = 0;
private Target targets[] = {
new Target("t1", 30, 50)
};
Radar(int w, int h) {
setSize(w, h);
}
Image img = ImageUtils.open();
public void paint(java.awt.Graphics g) {
java.awt.Dimension d = getSize();
double deltaTheta =
3 * Math.PI / 180.0;
int width = d.width;
int height = d.height;
int xc = width / 2;
int yc = height / 2;
g.setColor(java.awt.Color.green);
int r = Math.min(xc, yc);
double xr =
r * Math.cos(getThetaInRadians()) + xc;
double yr =
r * Math.sin(getThetaInRadians()) + yc;
setThetaInRadians(getThetaInRadians() + deltaTheta);
for (int i = 0; i < getTargets().length; i++)
getTargets()[i].draw(g);
if (img != null)
g.drawImage(img, 0, 0, width, height, this);
g.drawLine(xc, yc, (int) xr, (int) yr);
g.drawString("target", (int) xr, (int) yr);
repaint(1);
}
public static void main(String args[]) {
gui.ClosableJFrame cf = new gui.ClosableJFrame();
java.awt.Container c = cf.getContentPane();
c.add(new Radar(200, 200));
c.add(new Radar(200, 200));
c.setLayout(
new GridLayout(3, 3));
cf.setSize(200, 200);
cf.setVisible(true);
}
public double getThetaInRadians() {
return thetaInRadians;
}
public void setThetaInRadians(double thetaInRadians) {
this.thetaInRadians = thetaInRadians;
}
public Target[] getTargets() {
return targets;
}
public void setTargets(Target[] targets) {
this.targets = targets;
}
}