-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKochCurve.java
More file actions
44 lines (39 loc) · 1.02 KB
/
KochCurve.java
File metadata and controls
44 lines (39 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Write a description of class KochCurve here.
*
* @author Luke Bradaric
* @version (a version number or a date)
*/
import gpdraw.*;
public class KochCurve
{
private DrawingTool pen;
KochCurve(){
pen = new DrawingTool();
pen.turnRight(90);
}
private void drawKochCurve(int level, double length){
if(level < 1){
pen.down();
pen.forward(length);
}
else{
pen.up();
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 void drawCurve(int level, double length)
{
drawKochCurve(level, length);
pen.turnRight(120);
drawKochCurve(level, length);
pen.turnRight(120);
drawKochCurve(level, length);
}
}