public static void kochCurve(DWindow w, double x, double y,
double d, double a, int depth) {
if (depth <= 0) {
w.drawLine(x, y, x + d * cos(a), y - d * sin(a));
} else {
double d3 = d / 3;
kochCurve(w, x, y, d3, a, depth - 1);
x = x + d3 * cos(a); y = y - d3 * sin(a);
a = a + 60;
kochCurve(w, x, y, d3, a, depth - 1);
x = x + d3 * cos(a); y = y - d3 * sin(a);
a = a - 120;
kochCurve(w, x, y, d3, a, depth - 1);
x = x + d3 * cos(a); y = y - d3 * sin(a);
a = a + 60;
kochCurve(w, x, y, d3, a, depth - 1);
}
}
public static void kochSnowFlake(DWindow w, double x, double y,
double d, int depth) {
double a = 60;
for (int i = 0; i < 3; i++) {
kochCurve(w, x, y, d, a, depth);
x = x + d * cos(a); y = y - d * sin(a);
a = a - 120;
}
}
}
|