Skip to content
Snippets Groups Projects
Commit f03144cb authored by koz01's avatar koz01
Browse files

solution

parent a101a49c
No related merge requests found
...@@ -3,12 +3,17 @@ package lab; ...@@ -3,12 +3,17 @@ package lab;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class DrawingThread extends AnimationTimer { public class DrawingThread extends AnimationTimer {
private final Canvas canvas; private final Canvas canvas;
private final GraphicsContext gc; private final GraphicsContext gc;
private long previousTime;
private double x = 10;
private double y = 10;
private double speed = 20;
public DrawingThread(Canvas canvas) { public DrawingThread(Canvas canvas) {
this.canvas = canvas; this.canvas = canvas;
this.gc = canvas.getGraphicsContext2D(); this.gc = canvas.getGraphicsContext2D();
...@@ -20,11 +25,28 @@ public class DrawingThread extends AnimationTimer { ...@@ -20,11 +25,28 @@ public class DrawingThread extends AnimationTimer {
*/ */
@Override @Override
public void handle(long now) { public void handle(long now) {
// put your code here if (previousTime > 0) {
//gc.setFill(Color.AQUA); double deltaT = (now - previousTime) / 1e9;
//gc.setStroke(Color.BLACK); // put your code here
//gc.fillOval(10, 10, 20, 20); clearCanvas();
drawUFO(x, y);
x += speed * deltaT;
y += speed * deltaT;
}
previousTime = now;
}
private void clearCanvas() {
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
}
private void drawUFO(double x, double y) {
gc.setFill(Color.SILVER);
gc.fillOval(x, y, 50, 50);
gc.setFill(Color.BLACK);
gc.fillRect(x - 10, y + 25 - 1, 70, 2);
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment