2015-11-02 36 views
-3

它使半个雪花。如何使它成为一个完整的雪花?请帮助,以便我能够理解如何去做。源代码将不胜感激。如何制作雪花曲线?

import gpdraw.*; 

public class KochCurve 
{ 
private SketchPad myPaper; 
private DrawingTool myPencil; 

public KochCurve() 
{ 
myPaper = new SketchPad(600,600); 
myPencil = new DrawingTool(myPaper); 
} 

public void draw() 
{ 
drawKochCurve(6, 300); 
} 

private void drawKochCurve(double level, double sideLength) 
{ 
if(level < 1) 
    myPencil.forward(sideLength); 

else 
{ 
    drawKochCurve(level - 1, (sideLength)/3); 
    myPencil.turnLeft(60); 
    drawKochCurve(level - 1, (sideLength)/3); 
    myPencil.turnRight(120); 
    drawKochCurve(level - 1, (sideLength)/3); 
    myPencil.turnLeft(60); 
    drawKochCurve(level - 1, (sideLength)/3); 
    } 

    } 
    } 

回答

0

尝试“手动”运行算法:使用简单的笔在空白纸上执行提及的操作。你最终只画出半个雪花。这是因为drawKochCurve方法不会绘制所有的雪花边缘。