(* Programul deseneaza fractalul cruce in format SVG (Scalable vector graphics) http://en.wikipedia.org/wiki/Vicsek_fractal Compilati programul: ocamlc patrat.ml si apoi rulati ./a.out > patrat.svg Vizualizati fisierul SVG, de exemplu in browser *) open Printf let rec fig l x y = if l < 3. then ( (* deseneaza patrat *) printf "M %.1f %.1f " x y; (* muta cursorul la (x, y) *) printf "h %.1f" l; (* h = linie orizontala *) printf "v %.1f" l; (* v = linie verticala *) printf "h %.1f" (-.l); printf "v %.1f" (-.l) ) else let l3 = l /. 3. in let l23 = 2. *. l3 in let x23 = x +. l23 and y23 = y +. l23 in let fig3 = fig l3 in ( (* 5 figuri de latura l/3 *) fig3 x y; fig3 x23 y; fig3 (x +. l3) (y +. l3); fig3 x y23; fig3 x23 y23 ) let () = ( print_string "<?xml version=\"1.0\"?>\n\ <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n\ <path d=\""; fig 729. 0. 0.; print_string "\"/>\n</svg>" )
This document was generated using caml2html