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 45 46 47 48 49 50
package sample; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.image.PixelWriter; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; public class _floor 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 double SQUARE_L = 0.125; private void draw() { PixelWriter pw = gc.getPixelWriter(); boolean b_hanten = false, b_even; int x, y = -VIEW_H / 2, next_y; int n = 1; while (true) { next_y = (int)((-VIEW_H / 2) / (1 + n * SQUARE_L)); n++; if (y == next_y) break; for (; y < next_y; y++) { for (x = -VIEW_W / 2; x < VIEW_W / 2; x++) { b_even = ((int)(Math.abs(x / (y * 2 * SQUARE_L)) + 0.5) % 2 == 0); pw.setArgb(x + VIEW_W / 2, VIEW_H /2 - y, (b_even != b_hanten) ? 0xff000000 : 0xffffffff); } } b_hanten = !b_hanten; } } }