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

2023_eng_solution

parent a101a49c
No related merge requests found
package lab;
import javafx.animation.AnimationTimer;
import javafx.geometry.Point2D;
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 Point2D p = new Point2D(0, 100);
private Point2D v = new Point2D(50, 0);
private long lastTimeOffset = -1;
public DrawingThread(Canvas canvas) {
this.canvas = canvas;
......@@ -20,11 +29,26 @@ public class DrawingThread extends AnimationTimer {
*/
@Override
public void handle(long now) {
gc.setFill(Color.YELLOW);
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
paintUFO(p.getX(), p.getY());
if (lastTimeOffset >= 0) {
//compute simulation
double deltaT = (now - lastTimeOffset)/1e9;
p = new Point2D(p.getX() + v.getX()*deltaT,p.getY() + v.getY()*deltaT);
}
lastTimeOffset = now;
}
void paintUFO(double x, double y) {
// put your code here
//gc.setFill(Color.AQUA);
gc.setFill(Color.AQUA);
//gc.setStroke(Color.BLACK);
//gc.fillOval(10, 10, 20, 20);
gc.fillOval(15 + x, 0 + y, 30, 20);
gc.setFill(Color.SILVER);
gc.fillRect(0 + x, 8 + y, 60, 5);
}
}
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