import jlab.graphics.DWindow;
public class Fractal {
public static void main(String[] args) {
DWindow w = new DWindow(200, 200);
drawTree(w, 100, 200, 80, 90, 6); // วาดต้นไม้
// spskiTriangle(w, 10, 190, 180, 6); // วาดสามเหลี่ยม Sierpinski
// kochSnowFlake(w, 20, 150, 160, 4); // วาดเกล็ดหิมะ von Koch
}
public static void drawTree(DWindow w, double x0, double y0,
double d, double a, int depth) {
double x1 = x0 + d * cos(a), y1 = y0 - d * sin(a);
w.drawLine(x0, y0, x1, y1);
if (depth <= 0) return;
drawTree(w, x1, y1, 0.6 * d, a, depth - 1);
drawTree(w, x1, y1, 0.5 * d, a + 35, depth - 1);
drawTree(w, x1, y1, 0.5 * d, a - 35, depth - 1);
}
public static double sin(double a) {
return Math.sin(Math.toRadians(a));
}
public static double cos(double a) {
return Math.cos(Math.toRadians(a));
}
|