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

solution

parent a101a49c
Branches 2022_Wed_10-45
No related merge requests found
......@@ -3,12 +3,17 @@ package lab;
import javafx.animation.AnimationTimer;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class DrawingThread extends AnimationTimer {
private final Canvas canvas;
private final GraphicsContext gc;
private long previousTime;
private double x = 10;
private double y = 10;
private double speed = 20;
public DrawingThread(Canvas canvas) {
this.canvas = canvas;
this.gc = canvas.getGraphicsContext2D();
......@@ -20,11 +25,28 @@ public class DrawingThread extends AnimationTimer {
*/
@Override
public void handle(long now) {
// put your code here
//gc.setFill(Color.AQUA);
//gc.setStroke(Color.BLACK);
//gc.fillOval(10, 10, 20, 20);
if (previousTime > 0) {
double deltaT = (now - previousTime) / 1e9;
// put your code here
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