1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package sample;
import javafx.scene.canvas.GraphicsContext;
public class _turtle {
private GraphicsContext gc;
private double curr_a, curr_x, curr_y;
public _turtle(GraphicsContext gc) { this.gc = gc; }
public void angle(double a) { curr_a = a - (int)a / 360 * 360; }
public void turn(double a) { angle(curr_a + a); }
public void position(double x, double y) {
curr_x = x; curr_y = y;
gc.moveTo(x, y);
}
public void line(double len) {
double t = curr_a * Math.PI / 180;
curr_x += len * Math.cos(t);
curr_y += len * Math.sin(t);
gc.lineTo(curr_x, curr_y);
}
}