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

2023_Wed_900_koz01_solution

parent a101a49c
No related merge requests found
......@@ -3,11 +3,27 @@ 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 static final double FPS = 100;
private final Canvas canvas;
private final GraphicsContext gc;
private double p_x = 5;
private double p_y = 300;
private double v_x = 50;
private double v_y = -50;
private double g_y = 9.81;
private long previousTime;
public DrawingThread(Canvas canvas) {
this.canvas = canvas;
......@@ -20,11 +36,30 @@ public class DrawingThread extends AnimationTimer {
*/
@Override
public void handle(long now) {
if (previousTime > 0) {
double deltaT = (now - previousTime) / 1e9;
if (deltaT < 1/FPS) {
return;
}
p_x = p_x + v_x * deltaT;
p_y = p_y + v_y * deltaT;
v_y = v_y + g_y * deltaT;
}
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
drawUFO(p_x, p_y);
previousTime = now;
}
void drawUFO(double x, double y) {
// put your code here
//gc.setFill(Color.AQUA);
//gc.setStroke(Color.BLACK);
//gc.fillOval(10, 10, 20, 20);
gc.setFill(Color.SILVER);
gc.fillOval(15 + x, y, 30, 20);
gc.setFill(Color.INDIANRED);
gc.fillRect(x, 8 + y, 60, 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