Let's place people in their starting position now and draw a pretty map showing people's happiness at the start... Here's the code for this: |
let starting_placement = zip centers people let mismatches :: Person -> Person -> Int mismatches a b = length $ filter (uncurry (/=)) $ zip a b let similarityColor :: Person -> Person -> Color similarityColor p1 p2 = let m = mismatches p1 p2 h = div (length p1) 2 d = 30 * (abs (h - m)) b = max 0 (255-d) o = min d 255 in if m < h then (0,o,b) else (o,0,b) let findPerson :: Placement -> Point -> Person findPerson a p | Just (_,e) <- find ((== p).fst) a = e let similarityLine :: Placement -> Link -> (Color,Polygon) similarityLine l [p1,p2] = (similarityColor (findPerson l p1) (findPerson l p2),[p1,p2]) writeFile "tut8.svg" $ writePolygons $ map (similarityLine starting_placement) sitting
Here's what tut8.svg looks like: |
The only really important function in this block of code is the first line that calculates the starting_placement... This is just a zipped together list of the lot centers and people into spot-people pairs. The rest of the code is just for the eye candy... The color of the lines tells you how well two neighbors get along... The similarityColor function is a little kludge that creates a nice color from red to blue, depending on how compatible two people are (as usual in Haskell, the type signature of Person->Person->Color is pretty much a dead give-away...) |