Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Victor Lam, 10/19/12
- 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, double length)
- {
- /* The base case is a straight line
- * Else draw something like this _/\_
- */
- if(level == 0){
- 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);
- }
- }
- /*
- * Turn right and then draw the graph, rotate and then draw more
- * Draw until a snowflake
- */
- public void drawKoch(int level, int length){
- pen.turnRight();
- drawKochCurve(level, length);
- pen.turnRight(120);
- drawKochCurve(level, length);
- pen.turnRight(120);
- drawKochCurve(level, length);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement