java画圆函数是哪个_画圆用Java

我一直在做这个项目的最后一周和无法弄清楚如何解决它组成的分形图案。我觉得我很亲密,但无法发现我的错误! 我的任务需要我使用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值