Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. //Victor Lam, 10/19/12
  2. import gpdraw.*;
  3.  
  4. public class KochCurve
  5. {
  6.     private DrawingTool pen;
  7.     private SketchPad paper;
  8.    
  9.     public KochCurve()
  10.     {
  11.         paper = new SketchPad(500,500);
  12.         pen = new DrawingTool(paper);
  13.     }      
  14.  
  15.     public void drawKochCurve(int level, double length)
  16.     {
  17.         /* The base case is a straight line
  18.          * Else draw something like this _/\_
  19.          */
  20.         if(level == 0){
  21.             pen.forward(length);
  22.         }
  23.         else {    
  24.             drawKochCurve(level - 1, length/ 3);
  25.             pen.turnLeft(60);
  26.             drawKochCurve(level - 1, length/3);
  27.             pen.turnRight(120);
  28.             drawKochCurve(level - 1, length/3);
  29.             pen.turnLeft(60);
  30.             drawKochCurve(level - 1, length/3);        
  31.         }      
  32.     }
  33.    
  34.     /*
  35.      * Turn right and then draw the graph, rotate and then draw more
  36.      * Draw until a snowflake
  37.      */
  38.     public void drawKoch(int level, int length){
  39.         pen.turnRight();
  40.         drawKochCurve(level, length);
  41.         pen.turnRight(120);
  42.         drawKochCurve(level, length);
  43.         pen.turnRight(120);
  44.         drawKochCurve(level, length);                
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement