Advertisement
kburnik

LOGO - konveksna ljuska - rješenje

Nov 24th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. to cmp :a :b
  2. ifelse (first :a) = (first :b) [
  3. op (last :a) < (last :b)
  4. ][
  5. op (first :a) < (first :b)
  6. ]
  7. end
  8.  
  9. to convexhull :l
  10. (local "hull "index "kut "mink "p "rk "s )
  11. make "l (sort :l "cmp)
  12. make "s last :l
  13. make "p first :l
  14. make "kut 270
  15. pu setpos :p pd
  16. seth :kut
  17. make "hull []
  18. while [not :p = :s] [
  19. make "s first :l
  20. make "hull lput :p :hull
  21. make "mink normkut 359
  22. foreach :l [
  23. if not ? = :p [
  24. make "rk normkut ((towards ?) - :kut)
  25. if (:rk < :mink) [make "index # make "mink :rk]
  26. ]
  27. ]
  28. make "p item :index :l
  29. seth towards :p
  30. pu setpos :p pd
  31. make "kut heading
  32. ]
  33. op :hull
  34. end
  35.  
  36. to konveksni
  37. make "l []
  38. mouseon [ pu setpos mousepos pd ] [
  39. make "l lput mousepos :l cs foreach :l [pu setpos ? pd circle 3]
  40. ][][ mouseoff ljuska :l][]
  41. end
  42.  
  43. to ljuska :l
  44. localmake "hull convexhull :l
  45. pu setpos last :hull pd
  46. foreach :hull [ setpos ? ]
  47. end
  48.  
  49. to normkut :k
  50. localmake "h heading
  51. seth :k make "k heading seth :h
  52. op :k
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement