public void treblih turtle int if return turtle turnLeft -90 hilbert t

 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
public void treblih(T turtle, int n)
{
if (n == 0) return;
turtle.turnLeft(-90);
hilbert(turtle, n - 1);
turtle.Forward(10.0);
turtle.turnLeft(90);
treblih(turtle, n - 1);
turtle.Forward(10.0);
treblih(turtle, n - 1);
turtle.turnLeft(90);
turtle.Forward(10.0);
hilbert(turtle, n - 1);
turtle.turnLeft(-90);
}
private void hilbert(T turtle, int n)
{
if (n == 0) return;
turtle.turnLeft(90);
treblih(turtle, n - 1);
turtle.Forward(10.0);
turtle.turnLeft(-90);
hilbert(turtle, n - 1);
turtle.Forward(10.0);
hilbert(turtle, n - 1);
turtle.turnLeft(-90);
turtle.Forward(10.0);
treblih(turtle, n - 1);
turtle.turnLeft(90);
}
public void Rosetta(int n)
{
T turtle = new T(400.0, 400.0, 180.0, g, pen);//30
double length = 400 / n;
double angle = 360 / n;
for (int j = 0; j < 20; j++)
{
for (int i = 0; i < n; i++)
{
turtle.Forward(length);
turtle.turnLeft(angle);
}
turtle.turnLeft(18);
}
}
public static void koch(int n, double step, T turtle)
{
if (n == 0)
{
turtle.Forward(step);
return;
}
koch(n - 1, step, turtle);
turtle.turnLeft(60.0);
koch(n - 1, step, turtle);
turtle.turnLeft(-120.0);
koch(n - 1, step, turtle);
turtle.turnLeft(60.0);
koch(n - 1, step, turtle);
}
private void Serpinsky(T t, int order, double size)
{
if (order == 0)
{
t.Forward(size);
t.turnLeft(120);
t.Forward(size);
t.turnLeft(120);
t.Forward(size);
t.turnLeft(120);
}
else
{
Serpinsky(t, order - 1, size / 2);
t.Forward(size / 2);
Serpinsky(t, order - 1, size / 2);
t.Forward(size / 2);
t.turnLeft(120);
t.Forward(size);
t.turnLeft(120);
t.Forward(size / 2);
t.turnLeft(120);
Serpinsky(t, order - 1, size / 2);
t.turnRight(120);
t.Forward(size / 2);
t.turnLeft(120);
}