Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gpdraw.*;
- public class KochCurve {
- private DrawingTool pen;
- private SketchPad paper;
- public KochCurve(){
- paper = new SketchPad(500,500);
- pen = new DrawingTool(paper);
- }
- public void drawKochCurve(int level, int length) {
- if (level < 1)
- pen.forward(length);
- else {
- drawKochCurve(level - 1, length / 3);
- pen.turnLeft(60);
- drawKochCurve(level - 1, length / 3);
- pen.turnRight(120);
- drawKochCurve(level - 1, length / 3);
- pen.turnLeft(60);
- drawKochCurve(level - 1, length / 3);
- }
- }
- public static void main(String[] args) {
- KochCurve curve = new KochCurve();
- curve.drawKochCurve(6,300);
- }
- }
Add Comment
Please, Sign In to add comment