阅读背景:

试图制作koch雪花,但它不起作用?

来源:互联网 
import gpdraw.*;
import javax.swing.*;
import java.lang.Math;


public class Koch2 extends JFrame {

SketchPad paper;
DrawingTool pen;

public Koch2() {

    paper = new SketchPad(600, 600);
    pen = new DrawingTool(paper);

}


public void drawKoch(double sL, int level, double length) {

int x = level - 1;
double y = length / 3;

double z = -1.5 * sL;


if (level < 1) {
    pen.up();
    pen.move(z, 0);
    pen.down();
    pen.setDirection(0);
    pen.forward(sL);
}
else {
    pen.up();
    pen.move(z, 0);
    pen.down();
    pen.setDirection(0);
    pen.forward(length / (Math.pow(3, length)));
    pen.setDirection(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnLeft(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.setDirection(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));
    pen.setDirection(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnLeft(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.setDirection(60);
    pen.forward(length / (Math.pow(3, length)));
    pen.turnRight(120);
    pen.forward(length / (Math.pow(3, length)));


    /*pen.setDirection(0);
    pen.forward(length / (Math.pow(3, length)));
    */

    drawKoch((sL), (x) , (y));

}



}

public static void main(String[] args) {

    new Koch2().drawKoch(300, 6, 300);
}
}
import gpdraw.*;
import javax.swing.*;
import j



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: