You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

  1. #use "part4.ml"
  2. #use "simulation1.ml"
  3. (* Question 18 bonus *)
  4. let graphical_clip = fun q f ->
  5. let r = boundary q in
  6. let dparams = init r in
  7. let sx,sy,z = dparams in
  8. (* Draw initial QuadTree *)
  9. let _ = draw_quadtree dparams f q in
  10. (* Get 2 points *)
  11. let c1 = get_point dparams in
  12. let c2 = get_point dparams in
  13. let r' = make_rect c1 c2 in
  14. (* Debug *)
  15. let _ = Printf.printf "%s\n" (rect_tostring r') in
  16. (* Draw red rectangle and wait for key press *)
  17. let x1 = int_of_float (sx +. z *. rect_left r') in
  18. let y1 = int_of_float (sy +. z *. rect_bottom r') in
  19. let x2 = int_of_float (sx +. z *. rect_right r') in
  20. let y2 = int_of_float (sy +. z *. rect_top r') in
  21. let _ = Graphics.set_color Graphics.red in
  22. let _ = Graphics.draw_rect x1 y1 (x2-x1) (y2-y1) in
  23. let _ = Graphics.set_color Graphics.black in
  24. let _ = Graphics.wait_next_event [ Graphics.Key_pressed ] in
  25. (* Clip the QuadTree and draw it *)
  26. let _ = Graphics.close_graph in
  27. let q' = clip q r' in
  28. let dparams = init r' in
  29. let _ = draw_quadtree dparams f q' in
  30. let _ = wait_and_quit () in
  31. q'
  32. ;;
  33. let q = gen_random_quadtree (make_rect (0., 0.) (30., 30.)) 20 ;;
  34. let qbis = graphical_clip q (fun str -> str) ;;
  35. simple_test qbis (fun str -> str);;