我創建了一個sierpinski三角形代碼。但是我想根據代碼所做的三角形陰影三角形。在我的情況下,我只打印沒有陰影的三角形。我想要類似這樣的東西! http://en.wikipedia.org/wiki/File:Sierpinski_triangle_evolution.svg我如何遮蔽sierpinski三角形?
組2:Kulplex
學生:亨利蕩
我應該怎麼辦?
import java.applet.*;
import java.awt.*;
public class Sierpinski extends Applet {
/**
*
*/
private static final long serialVersionUID = 1L;
Graphics g;
Point a1,b1,c1, a2,b2,c2, a3,b3,c3;
int deep = 0;
public void paint() {
setBackground(new Color(255,255,255));
}
public boolean mouseDown(Event ev, int x, int y) {
if (!ev.metaDown()) deep += 1;
else if (deep>0) deep -= 1;
repaint();
return true;
}
public void paint(Graphics g) {
// Create triangle
int px[] = {20, 400, 210};
int py[] = {400, 400, 20};
g.drawPolygon(px, py, 3);
paintTriangle(g, new Point(20,400),new Point(400,400),new Point(210,20), deep);
}
public void paintTriangle(Graphics g, Point a, Point b, Point c, int lvl) {
if (lvl==0) return;
lvl -= 1;
// In the given triangle, amended to include an upside-down triangle
int px[] = {c.x, (c.x+b.x)/2, (a.x+c.x)/2};
int py[] = {b.y, (c.y+a.y)/2, (c.y+a.y)/2};
g.drawPolygon(px, py, 3);
// 3 new triangles
a1 = a;
b1 = new Point(c.x, b.y);
c1 = new Point((a.x+c.x)/2, (c.y+a.y)/2);
paintTriangle(g, a1, b1, c1, lvl);
a2 = new Point(c.x, b.y);
b2 = b;
c2 = new Point((c.x+b.x)/2, (c.y+a.y)/2);
paintTriangle(g, a2, b2, c2, lvl);
a3 = new Point((a.x+c.x)/2, (c.y+a.y)/2);
b3 = new Point((c.x+b.x)/2, (c.y+a.y)/2);
c3 = c;
paintTriangle(g, a3, b3, c3, lvl);
}
}
代碼忽略 –
2012-02-15 14:33:27
什麼是「蔭」呢?塗上不同的顏色? – DRCB 2012-02-15 14:44:20
在這種情況下,陰影意味着我想陰影我繪製的tracingles,因爲這裏的三角形是透明的。 – 2012-02-15 14:49:41