Java - Circle Fractal

时间:2017-03-22 23:21:26

标签: java fractals

请帮帮我!我绘制圆形分形但我只能绘制左侧或右侧。我怎样画双方?

enter image description here

public class ZZZ {
public static void main(String[] args) {
StdDraw.setCanvasSize(1024,1024);
StdDraw.setXscale(-15,15);
StdDraw.setYscale(-15,15);
double x=0.0;
double y=0.0;
double r=5.0;
StdDraw.setPenRadius(0.01);
StdDraw.circle(x, y, r);
    int j=StdRandom.uniform(2);
    for(int s=1;s<10;s++){
    x=x+r;
    r=r/3*2;
    StdDraw.circle(x, y, r);
    }
    int k=StdRandom.uniform(2);
    for(int i=1;i<10;i++){
    x=x-r;
    r=r/3*2;
    StdDraw.circle(x, y, r);
    }}}

1 个答案:

答案 0 :(得分:1)

在第二个x循环中绘制圆圈之前,您应该将0重置回r并将5重置回for。所以你的代码应如下所示:

public class ZZZ {
    public static void main(String[] args) {
        StdDraw.setCanvasSize(1024,1024);
        StdDraw.setXscale(-15,15);
        StdDraw.setYscale(-15,15);

        double x=0.0;
        double y=0.0;
        double r=5.0;

        StdDraw.setPenRadius(0.01);
        StdDraw.circle(x, y, r);

        int j=StdRandom.uniform(2);
        for(int s=1;s<10;s++){
            x=x+r;
            r=r/3*2;
            StdDraw.circle(x, y, r);
        }

        x = 0.0;
        r = 5.0;
        int k=StdRandom.uniform(2);
        for(int i=1;i<10;i++){
            x=x-r;
            r=r/3*2;
            StdDraw.circle(x, y, r);
        }
    }
}