62 lines
1.5 KiB
Java
62 lines
1.5 KiB
Java
import org.jfree.fx.FXGraphics2D;
|
|
|
|
import java.awt.*;
|
|
import java.awt.geom.Line2D;
|
|
|
|
public class MovingLine {
|
|
|
|
private MovingPoint beginPoint;
|
|
private MovingPoint endPoint;
|
|
private Color color;
|
|
|
|
private int counter = 0;
|
|
|
|
private int MAX_LINES = 30;
|
|
|
|
private Line2D.Double[] trailingLines;
|
|
|
|
public MovingLine(MovingPoint beginPoint, MovingPoint endPoint, Color color) {
|
|
this.beginPoint = beginPoint;
|
|
this.endPoint = endPoint;
|
|
this.color = color;
|
|
|
|
trailingLines = new Line2D.Double[MAX_LINES];
|
|
}
|
|
|
|
public void draw(FXGraphics2D graphics) {
|
|
graphics.setColor(color);
|
|
graphics.draw(getAsLine());
|
|
|
|
for (int i = trailingLines.length-1; i >= 0; i--) {
|
|
if (trailingLines[i] != null)
|
|
graphics.draw(trailingLines[i]);
|
|
}
|
|
}
|
|
|
|
public void update() {
|
|
this.beginPoint.update();
|
|
this.endPoint.update();
|
|
|
|
counter++;
|
|
if (counter == MAX_LINES) {
|
|
counter = 0;
|
|
}
|
|
|
|
for (int i = trailingLines.length-1; i > 0; i--) {
|
|
trailingLines[i] = trailingLines[i-1];
|
|
}
|
|
|
|
trailingLines[0] = getAsLine();
|
|
|
|
}
|
|
|
|
public void setMovingBounds(double canvasWidth, double canvasHeight) {
|
|
this.beginPoint.setMovingBounds(canvasWidth, canvasHeight);
|
|
this.endPoint.setMovingBounds(canvasWidth, canvasHeight);
|
|
}
|
|
|
|
public Line2D.Double getAsLine() {
|
|
return new Line2D.Double(beginPoint.getxPos(), beginPoint.getyPos(), endPoint.getxPos(), endPoint.getyPos());
|
|
}
|
|
}
|