open Printf let bend = acos (sqrt 0.5) (* unghiul de aplecare, pi/4 *) let rat = 2. (* raportul de micsorare *) let side = 400. (* inaltimea figurii *) let rec treefract len phi = let branch phi1 = (* una din cele doua ramuri *) let dx = len *. cos phi1 and dy = len *. sin phi1 in printf " l %.1f %.1f" dx dy; (* linie relativa la pct curent *) treefract (len /. rat) phi1; (* copac mai mic, unghi nou *) printf " m %.1f %.1f" (-.dx) (-.dy); (* muta inapoi *) in if (len > 1.) then ( (* stop la <= 1 pixel *) branch (phi +. bend); branch (phi -. bend); ) let () = ( 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=\""; printf "M %.1f %.1f" side side; (* origine: jos mijloc; segment: 1/2 inaltime; directie: sus = 3*pi/2 *) treefract (side /. 2.) (asin (-1.)); print_string "\"/>\n</svg>" )
This document was generated using caml2html