2015-11-02 81 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方法不會繪製所有的雪花邊緣。