1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| open Graphics;;
let draw_triangle (xa, ya) (xb, yb) (xc, yc) =
moveto xa ya;
lineto xb yb ;
lineto xc yc;
lineto xa ya;
;;
let ( // ) (x1, y1) (x2, y2) = ((x1 + x2)/2, (y1 + y2)/2)
let rec sierpinski (xa, ya) (xb, yb) (xc, yc) =
function
| 0 -> ()
| acc -> (
draw_triangle (xa, ya) (xb, yb) (xc, yc);
sierpinski (xa, ya) ((xa, ya) // (xb, yb)) ((xa, ya) // (xc, yc)) (acc-1);
sierpinski (xb, yb) ((yb, yb) // (xa, ya)) ((xb, yb) // (xc, yc)) (acc-1);
sierpinski (xc, yc) ((xc, yc) // (xa, ya)) ((xb, yb) // (xc, yc)) (acc-1);
)
;;
auto_synchronize false;
open_graph " 800x800";
sierpinski (0,0) (400,800) (800,0) 9;;
synchronize ();;
ignore (read_key ());; |
Partager