1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package sample;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class _toothed_wheel extends Application {
public static void main(String... args) {
Application.launch(args);
}
private static final int VIEW_W = 400, VIEW_H = 300;
private GraphicsContext gc;
@Override
public void start(Stage stage) throws Exception {
BorderPane pane = new BorderPane();
Scene scene = new Scene(pane);
stage.setScene(scene);
Canvas view = new Canvas(VIEW_W, VIEW_H);
pane.setCenter(view);
gc = view.getGraphicsContext2D();
draw();
stage.show();
}
private static final int NUM_TOOTH = 20;
private static final double
IN_R = 100, OUT_R = 110, DT = 5;
private void draw() {
gc.setTransform(1, 0, 0, -1, VIEW_W / 2, VIEW_H / 2);
gc.setLineWidth(2);
gc.beginPath();
double t, r;
for (int i = 0; i < 2 * NUM_TOOTH; i++) {
t = (double)(360 * i) / (2 * NUM_TOOTH);
r = (i % 2 == 0) ? IN_R : OUT_R;
gc.arc(0, 0, r, r, t - DT / 2, DT);
}
gc.closePath();
gc.stroke();
}
}