swamp_agr (swamp_agr) wrote,
swamp_agr
swamp_agr

Ещё не видел такой переносимости кода из одного фреймворка в другой

Леплю код на скорую руку, не обращая внимания на гвозди, которыми прибиваю рисунок к полотну.

Было:
     let ax = fst (_saggingLine $ allParams a)
         ay = snd (_saggingLine $ allParams a)
         lx = abs (head ax - max')
         max' = maximum $ map abs ax
         half' = max' / 2
         ly = abs (head ay - last ay)
         bx = map (cm . (+6.0) . (/ lx) . (* 2.0) . negate) ax
         by = map (cm . (+2.0) . (/ ly) . (* 10.0)) ay
         cz = zip by bx
         drawLine a b = createLine a [coord b, filling "black"]
         drawText :: Canvas -> (Double,Double,String,(FontFamily,FontSlant,Int)) -> IO TextItem
         drawText a (b,c,d,e) = createTextItem a [position (cm b, cm c), text d, font e]
         drawText' :: Canvas -> (Double,Double,String,(FontFamily,FontWeight,Int)) -> IO TextItem
         drawText' a (b,c,d,e) = createTextItem a [position (cm b, cm c), text d, font e]
         hr10 = (Helvetica,Roman,10::Int)
       in do mapM_ (drawLine canv) [ cz, [(cm 2, cm 6), (cm 12, cm 6)], [(cm 2, cm 7), (cm 12, cm 7)]
                                   , [(cm 2, cm 8), (cm 12, cm 8)], [(cm 2, cm 6), (cm 2, cm 8)]
                                   , [(cm 12, cm 6), (cm 12, cm 8)] ]

стало:
  let ax = fst (_saggingLine $ allParams a)
      ay = snd (_saggingLine $ allParams a)
      lx = abs (head ax - max')
      max' = maximum $ map abs ax
      half' = max' / 2
      ly = abs (head ay - last ay)
      bx = map (floor . (+180.0) . (/ lx) . (* 70.0) . negate) ax
      by = map (floor . (+40.0) . (/ ly) . (* 320.0)) ay
      cz = zip by bx
      pts = map (\(x,y) -> Point x y) cz
    in do polyline dc pts [ penCap := CapButt
                       , penKind := PenSolid
                       , penWidth := 2
                       , color := rgb 0 0 0
                       ]
  mapM_ (line' dc [penCap := CapButt, penKind := PenSolid, penWidth := 2, color := rgb 0 0 0]) 
    [ (Point 40 35, Point 40 115)
    , (Point 360 35, Point 360 115)
    , (Point 40 180, Point 40 250)
    , (Point 360 180, Point 360 250)
    ]
Tags: gui, haskell, wxwidgets
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments