画正方体的3D分形
private void Digui(Point p0, int width) {
Point p1 = new Point();
Point p2 = new Point();
Point p3 = new Point();
Point p4 = new Point();
Point pa = new Point();
Point pb = new Point();
Point pc = new Point();
Point pd = new Point();
for (int i = 2; i >=0; i--) {
for (int j =2; j >= 0; j--) {
for (int k = 0; k < 3; k++) {
p1.x = (int) (p0.x + width / 3 * k + j
* ((width - width / 4) / 3 * 1.41 / 2));
p1.y = (int) (p0.y - j
* ((width - width / 4) / 3 * 1.41 / 2) + i * width
/ 3);
p2.x = (int) (p0.x + width / 3 * (k + 1) + j
* ((width - width / 4) / 3 * 1.41 / 2));
p2.y = p1.y;
p3.x = p2.x;
p3.y = p2.y + width / 3;
p4.x = p1.x;
p4.y = p3.y;
pa.x = (int) (p1.x + ((width - width / 4) / 3 * 1.41 / 2));
pa.y = (int) (p1.y - ((width - width / 4) / 3 * 1.41 / 2));
pb.x = pa.x + width / 3;
pb.y = pa.y;
pc.x = pb.x;
pc.y = pb.y + width / 3;
pd.x = pa.x;
pd.y = pc.y;
if (i != 1 && k != 1 || i != 0 && k != 1 && j != 1
|| j != 1 && k != 2 && i != 1 || k != 0 && i != 1
&& j != 1 || i != 2 && j != 1 && k != 1) {
int[] array1x = { p1.x, p2.x, p3.x, p4.x };
int[] array1y = { p1.y, p2.y, p3.y, p4.y };
gra.setColor(Color.GRAY);
gra.fillPolygon(array1x, array1y, 4);
int[] array2x = { pa.x, pb.x, p2.x, p1.x };
int[] array2y = { pa.y, pb.y, p2.y, p1.y };
gra.setColor(Color.darkGray);
gra.fillPolygon(array2x, array2y, 4);
int[] array3x = { p2.x, pb.x, pc.x, p3.x };
int[] array3y = { p2.y, pb.y, pc.y, p3.y };
gra.setColor(Color.BLACK);
gra.fillPolygon(array3x, array3y, 4);
if (width / 3 > 10) {
Digui(p1, width / 3);
}
}
}
}
}
}
- class='magplus' title='点击查看原始大小图片' />
- 大小: 19.6 KB