2d配列に円を描く関数を検索しました。
私は、周りの数学的方程式を使うのが最善の方法であることを発見しました。このコードでは2d配列で完全な円を描く
私は円の1/4を取得し、私はそれを「完了」するのか分かりません。
array
目的:私はあなたが理解してほしいよ押されたボタン
System.out.println("\nwait button pression\n");
while(true){
if(premuto.get()==true){
if(pos!=null){
if(pos.length()!=0){
break;
}
}
}
}
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
i1=this.getIntI();//get the coordinates of the button pressed
j1=this.getIntJ();// "
if(unita[i1][j1]!=null){ //control if the posistion isnt empty
int ir=i1-unita[i1][j1].getAtkRange();//calculate the 00 point of the square .see image "array"
int jr=j1-unita[i1][j1].getAtkRange();
ImageIcon icon= new ImageIcon(MyFrame.class.getResource("test.png"));
for (int i=ir ; i<(ir+(unita[i1][j1].getAtkRange()*2)) ; i++){
for (int j=jr ; j<(jr+unita[i1][j1].getAtkRange()*2) ;j++){//1st edit, changed the condition
if(((i - i1) * (i - i1) + (j - j1) * (j - j1)) <= unita[i1][j1].getAtkRange() * unita[i1][j1].getAtkRange()){
btnArray[i][j].setIcon(icon);
}
}
}
}
の周りに円を描きます。助けてくれてありがとう。
第一EDIT:ヨッシVainshteinへ 最初イム感謝:私は条件に
i< ir + (unita[i1][j1].getAtkRange()*2)
を設定した場合、プログラムが半円形を作成するので、私は条件2を変更し、それが動作しますが、ない完璧。ここに画像があります:最初の画像を確認してください。
結論:今、それは条件2で動作します:
i<= ir + (unita[i1][j1].getAtkRange()*2)
愚かな質問かもしれないが、なぜGraphics2D.drawOval()を使用しないでください – qry
あなたはhav 'pos'が何であるかを教えてください。ループがなぜ早すぎるのかを知る方法はありません。 –
グラフィック円/楕円形を描画し、コントロールや計算を行うための値が必要なだけです –