16×16の座標の中に半径7.7の円を描く。
16×16の座標の中に、算術関数で半径7.7の円を描く。
実数の軌跡は整数の精度で座標に描画され、円が現れる。
import static java.lang.Math.*; import java.util.Arrays; class Circle { public static void main(String[] args) throws java.lang.Exception { int field[][] = new int[16][16]; double r = 7.7; double a = 180; for (int i = 1; i <= 360; i++) { int x = (int) (r * cos(i * PI / a) + 8); int y = (int) (r * sin(i * PI / a) + 8); field[x][y] = 1; } for (int m = 0; m < 16; m++) { System.out.println(Arrays.toString(field[m])); } } }
stdout
[0, 0, 0, 0, 2, 7, 8, 7, 8, 8, 7, 2, 0, 0, 0, 0] [0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0] [0, 0, 9, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 9, 0, 0] [0, 7, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, 0] [2, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 2] [7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7] [8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8] [8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7] [7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8] [8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8] [7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7] [2, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 2] [0, 7, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, 0] [0, 0, 9, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 9, 0, 0] [0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0] [0, 0, 0, 0, 2, 7, 8, 8, 7, 8, 7, 2, 0, 0, 0, 0]