나는 지난 주 동안이 프로젝트를 진행 해왔고 수정 방법을 알 수 없습니다. 나는 너무 가깝지만 내 실수를 발견 할 수없는 것 같아! 자바 그래픽 클래스를 사용하여 가상 라인을 따라 원을 그려야합니다. 반지름이 n 인 가운데에 원을 그립니다. 그런 다음 끝점이 원의 왼쪽 및 오른쪽 호와 교차하는 반경이 n/2 인 두 개의 원을 그립니다.자바를 사용하여 원으로 구성된 프랙탈 패턴 그리기
저는 두 원의 두 번째 단계를 첫 번째 원의 오른쪽과 왼쪽으로 그릴 수있었습니다. 그러나 내 프로그램은 동일한 크기의 4 개의 원을 재귀 적으로 그려야합니다. 왼쪽 원의 오른쪽과 왼쪽 모두에 하나의 원이 있고 오른쪽 원의 오른쪽과 왼쪽 모두에 원이 하나 있습니다. 내 코드로 뭔가 의심 스럽다.
도움을 주시면 감사하겠습니다.
package fractalcircles;
import java.awt.*;
import javax.swing.*;
public class FractalCircles {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{ //create a MyCanvas object
MyCanvas canvas1 = new MyCanvas();
//set up a JFrame to hold the canvas
JFrame frame = new JFrame();
frame.setTitle("FractalCircles.java");
frame.setSize(500,500);
frame.setLocation(100,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//add the canvas to the frame as a content panel
frame.getContentPane().add(canvas1);
frame.setVisible(true);
}//end main
}//end class
class MyCanvas extends Canvas
{
public MyCanvas()
{} //end MyCanvas() constructor
//this method will draw the initial circle and invisible line
public void paint (Graphics graphics)
{
int x1,x2,y1,y2; //future x and y coordinates
int radius=125; //radius of first circle
int xMid=250, yMid=250; //center point (x,y) of circle
//draw invisible line
graphics.drawLine(0,250,500,250);
//draw first circle
graphics.drawOval(xMid-radius,yMid-radius,radius*2,radius*2);
//run fractal algorithm to draw 2 circles to the left and right
drawCircles(graphics, xMid, yMid, radius);
}
void drawCircles (Graphics graphics, int xMid, int yMid, int radius)
{
//used to position left and right circles
int x1 = xMid-radius-(radius/2);
int y1 = yMid-(radius/2);
int x2 = xMid+radius-(radius/2);
int y2= yMid-(radius/2);
if (radius > 5)
{
//draw circle to the left
graphics.drawOval(x1, y1, (radius/2)*2, (radius/2)*2);
//draw circle to the right
graphics.drawOval(x2, y2, (radius/2)*2, (radius/2)*2);
}
drawCircles (graphics, xMid, yMid, radius/2);
}