-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMooreCurve.java
More file actions
71 lines (63 loc) · 1.41 KB
/
MooreCurve.java
File metadata and controls
71 lines (63 loc) · 1.41 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package turtleClasses;
import java.awt.Color;
import turtleClasses.lib.Turtle;
import turtleClasses.lib.World;
public class MooreCurve {
public static Turtle t;
public static final int MAX = 7;
public static final int F = 5;
public static int color = 0;
/*public static final Color[] colors = {
Color.RED,
Color.ORANGE,
Color.YELLOW,
Color.GREEN,
Color.CYAN,
Color.BLUE,
Color.MAGENTA,
Color.PINK,
Color.GRAY,
Color.BLACK
};*/
public static void LMoores(int depth) {
if (depth >= MAX) {
return;
}
t.setColor(Color.BLUE);
t.turnLeft(); //-
RMoores(depth + 1); //R
t.forward(F); //F
t.turnRight(); //+
LMoores(depth + 1); //L
t.forward(F); //F
LMoores(depth + 1); //L
t.turnRight(); //+
t.forward(F); //F
RMoores(depth + 1); //R
t.turnLeft(); //-
//t.setColor(colors[color++ % colors.length]);
}
public static void RMoores(int depth) {
if (depth >= MAX) {
return;
}
t.setColor(Color.RED);
t.turnRight(); //+
LMoores(depth + 1); //L
t.forward(F); //F
t.turnLeft(); //-
RMoores(depth + 1); //R
t.forward(F); //F
RMoores(depth + 1); //R
t.turnLeft(); //-
t.forward(F); //F
LMoores(depth + 1); //L
t.turnRight(); //+
//t.setColor(colors[depth % colors.length]);
}
public static void main (String[] args) {
World w = new World(1000,1000);
t = new Turtle(1000,1000,w);
LMoores(0);
}
}