Guest User

Untitled

a guest
Feb 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import gpdraw.*;
  2.  
  3. public class KochCurve {
  4. private DrawingTool pen;
  5. private SketchPad paper;
  6.  
  7. public KochCurve(){
  8. paper = new SketchPad(500,500);
  9. pen = new DrawingTool(paper);
  10. }
  11.  
  12. public void drawKochCurve(int level, int length) {
  13. if (level < 1)
  14. pen.forward(length);
  15. else {
  16. drawKochCurve(level - 1, length / 3);
  17. pen.turnLeft(60);
  18. drawKochCurve(level - 1, length / 3);
  19. pen.turnRight(120);
  20. drawKochCurve(level - 1, length / 3);
  21. pen.turnLeft(60);
  22. drawKochCurve(level - 1, length / 3);
  23. }
  24. }
  25.  
  26. public static void main(String[] args) {
  27. KochCurve curve = new KochCurve();
  28. curve.drawKochCurve(6,300);
  29. }
  30. }
Add Comment
Please, Sign In to add comment