Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- to cmp :a :b
- ifelse (first :a) = (first :b) [
- op (last :a) < (last :b)
- ][
- op (first :a) < (first :b)
- ]
- end
- to convexhull :l
- (local "hull "index "kut "mink "p "rk "s )
- make "l (sort :l "cmp)
- make "s last :l
- make "p first :l
- make "kut 270
- pu setpos :p pd
- seth :kut
- make "hull []
- while [not :p = :s] [
- make "s first :l
- make "hull lput :p :hull
- make "mink normkut 359
- foreach :l [
- if not ? = :p [
- make "rk normkut ((towards ?) - :kut)
- if (:rk < :mink) [make "index # make "mink :rk]
- ]
- ]
- make "p item :index :l
- seth towards :p
- pu setpos :p pd
- make "kut heading
- ]
- op :hull
- end
- to konveksni
- make "l []
- mouseon [ pu setpos mousepos pd ] [
- make "l lput mousepos :l cs foreach :l [pu setpos ? pd circle 3]
- ][][ mouseoff ljuska :l][]
- end
- to ljuska :l
- localmake "hull convexhull :l
- pu setpos last :hull pd
- foreach :hull [ setpos ? ]
- end
- to normkut :k
- localmake "h heading
- seth :k make "k heading seth :h
- op :k
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement