class Sierpins { static void sierpins(DrawingWindow w, int n, // niveau de récursion demandé float xa, float ya, // coordonnées du point A float xb, float yb, // coordonnées du point B float xc, float yc) // coordonnées du point B { if (n == 0) { w.drawTriangle(Math.round(xa), Math.round(ya), Math.round(xb), Math.round(yb), Math.round(xc), Math.round(yc)); } else { float xd = (xa + xb) / 2; float yd = (ya + yb) / 2; float xe = (xb + xc) / 2; float ye = (yb + yc) / 2; float xf = (xc + xa) / 2; float yf = (yc + ya) / 2; sierpins(w, n - 1, xa, ya, xd, yd, xf, yf); sierpins(w, n - 1, xb, yb, xe, ye, xd, yd); sierpins(w, n - 1, xc, yc, xf, yf, xe, ye); } } public static void main(String[] args) { DrawingWindow w = new DrawingWindow("Sierpins", 640, 480); sierpins(w, 10, w.width / 2.0f, 0, 0, w.height - 1, w.width - 1, w.height - 1); } }