I am trying to make a koch snowflake using recursion and gpdraw in java. I can make the actual koch curve itself but i dont know how to make it come all the way around and make a snowflake.
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);
}
}
}
You will have to paint the same curve in each of the three directions of a triangle. You can do this by writing a function drawKochCurve(double level, double sideLength, double additionalAngle) and calling it three times, adding the additionalAngle.
Wikipedia has more details: The Koch curve originally described by Koch is constructed with only one of the three sides of the original triangle. In other words, three Koch curves make a Koch snowflake. http://en.wikipedia.org/wiki/Koch_snowflake