我一直在做这个项目的最后一周和无法弄清楚如何解决它组成的分形图案。我觉得我很亲密,但无法发现我的错误! 我的任务需要我使用Java Graphics类来沿着想象的线绘制圆。在半径为n的中心绘制一个圆。然后绘制两个半径为n/2的圆,其圆点的端点与圆弧的左圆弧和右圆弧相交。画圆用Java

我已经能够画两个圈到右侧的第2步,离开了第一圈。然而,我的程序应该画出四个相同大小的递归递归的圆。向左圆的右侧和左侧一个圆,以及向右圆的右侧和左侧一个圆。我的代码有可疑的东西。

任何帮助将不胜感激。

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);
}

2014-02-18

zhughes3