Skip to content

Instantly share code, notes, and snippets.

@kig
Created December 10, 2008 18:59
Show Gist options
  • Save kig/34439 to your computer and use it in GitHub Desktop.
Save kig/34439 to your computer and use it in GitHub Desktop.
cairo drawing lib bits with combinators
-- cairo drawing lib bits with combinators
moveToP = uncurry moveTo
lineToP = uncurry lineTo
curveToP ((x1,y1),(x2,y2),(x3,y3)) = curveTo x1 y1 x2 y2 x3 y3
doWith g f x = do { f x; g }
withDo f g x = do { f; g x }
listDo _ _ [] = return ()
listDo f g (x:xs) = do { f x; g xs }
tupleDo f g (x,y) = do { f x; g y }
fillWith = doWith fill
strokeWith = doWith stroke
closePathWith = doWith closePath
fillPolygon = fillWith drawPolygon
strokePolygon = strokeWith drawPolygon
strokeOpenPolygon = strokeWith drawOpenPolygon
drawPolygon = closePathWith drawOpenPolygon
drawOpenPolygon = withDo newPath drawSubPolygon
drawSubPolygon = listDo moveToP addToPolygon
addToPolygon = mapM_ lineToP
fillPath = fillWith drawPath
strokePath = strokeWith drawPath
strokeOpenPath = strokeWith drawOpenPath
drawPath = closePathWith drawOpenPath
drawOpenPath = withDo newPath drawSubPath
drawSubPath = tupleDo moveToP addToPath
addToPath = mapM_ curveToP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment