Arboresent肺也可看成是一种Koch曲线。 在线工作 源码下载 生成原理: 初始是两个顶角为钝角的等腰三角形,它们有一个公共的锐角极点(下图中n=0的情况)。从这个极点启航,等腰三角形的长边变成有一个夹角的两个等腰三角形,这两个小等腰三角形与正本的三角形具有相似联络,相似比为三角形的腰的长度和底边长度的比值。 javafx完结中间代码: public void draw1(Graphics http://www.360111.info Context gc, double x, double y, double size,
double prate, double alfa, double theta, double t, int level) {
double xe, ye, xa, ya, xb, yb, xc, yc, xd, yd, l;
l = size / prate;
xe = x;
ye = y;
xa = x size * Math.cos(alfa);
ya = y size * Math.sin(alfa);
xb = x l * Math.cos(alfa - theta);
yb = y l * Math.sin(alfa - theta);
xc = x l * Math.cos(alfa - theta - t);
yc = y l * Math.sin(alfa - theta - t);
xd = x size * Math.cos(alfa - theta * 2 - t);
yd = y size * Math.sin(alfa - theta * 2 - t);
if (level == 1) {
gc.setStroke(Color.RED);
gc.strokeLine(xa, ya, xe, ye);
gc.strokeLine(xe, ye, xd, yd);
gc.strokeLine(xd, yd, xc, yc);
gc.strokeLine(xc, yc, xe, ye);
gc.strokeLine(xe, ye, xb, yb);
gc.strokeLine(xb, yb, xa, ya);
} else {
draw1(gc, xb, yb, l, prate, (alfa - theta Math.PI), theta, t,
level - 1);
draw1(gc, xc, yc, l, prate, (alfa - theta - t Math.PI), -theta,
-t, level - 1);
}
}
效果图: 在线工作 源码下载 http://www.fpshijiazhuang.com