我有以下代码,如您所见,pencil.forward();
当我的边看起来不相等时,我每次都将相同的值除以 3。代码:
import gpdraw.*;
public class buildShape {
public SketchPad paper = new SketchPad(500,500);
public DrawingTool pencil = new DrawingTool(paper);
public void drawKochCurve(int level, double initialSize){
if (level < 1){
pencil.forward(initialSize);
} else {
drawKochCurve(level - 1, initialSize);
pencil.forward(initialSize / 3);
pencil.turnLeft(60);
pencil.forward(initialSize / 3);
pencil.turnRight(120);
pencil.forward(initialSize / 3);
pencil.turnLeft(60);
pencil.forward(initialSize / 3);
}
}
}
主要的:
public class Main {
public static void main(String[] args){
buildShape myKoch = new buildShape();
myKoch.drawKochCurve(1,90);
}
}