(* Programul deseneaza fractalul cruce in format SVG (Scalable vector graphics)
   http://en.wikipedia.org/wiki/Vicsek_fractal
   Compilati programul: ocamlc fractp.ml si apoi rulati ./a.out > patrat.svg
   Vizualizati fisierul SVG, de exemplu in browser *)

open Printf
  
let rec figp x y len =
  if len < 3. then ( (* caz baza - deseneaza patrat *)
    printf "M %.1f %.1f " x y;        (* muta cursorul la x, y *)
    printf "h %.1f " len;        (* linie orizontala *)
    printf "v %.1f " len;        (* linie verticala *)
    printf "h %.1f " (-. len);
    printf "v %.1f " (-. len);
  ) else
    let l3 = len /. 3. in (  (* 5 figuri mai mici *)
      figp x y l3;
      figp (x +. 2.*.l3) y l3;
      figp (x +. l3) (y +. l3) l3;
      figp x (y +. 2.*.l3) l3;
      figp (x +. 2.*.l3) (y +. 2.*.l3) l3
    )

let boxf len = (
  print_string "<?xml version=\"1.0\"?>\n\
  <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n\
  <path fill=\"none\" stroke=\"blue\" d=\"";
  figp 0. 0. len;
  print_string "\"/>\n</svg>"
)
;;
boxf 729.

This document was generated using caml2html