After meaning to get around to it for quite a while, I’ve finally released version 0.2 of the Haskell diagrams library. Here’s the release announcement. And here’s one of my favorite examples showing off the new path support:

Heighway dragon
I made this Heighway dragon curve in just a few minutes of hacking this afternoon, with the following code:
{- Heighway dragon. See http://en.wikipedia.org/wiki/Dragon_curve. -}
module Main where
import Graphics.Rendering.Diagrams
import Control.Monad.State
import Data.Maybe
dragonStr :: Int -> String
dragonStr 0 = "FX"
dragonStr n = concatMap rules $ dragonStr (n-1)
where rules 'X' = "X+YF+"
rules 'Y' = "-FX-Y"
rules c = [c]
strToPath :: String -> Path
strToPath s = pathFromVectors . catMaybes $ evalState c (0,-1)
where c = mapM exec s
exec 'F' = Just `fmap` get
exec '-' = modify left >> return Nothing
exec '+' = modify right >> return Nothing
exec _ = return Nothing
left (x,y) = (-y,x)
right (x,y) = (y,-x)
dragon :: Int -> Diagram
dragon = lc red . curved 0.8 . strToPath . dragonStr
main = renderAs PNG "dragon.png" (Width 300) (dragon 12)
A special thank you to Dougal Stanton for adding text rendering support and other features, switching diagrams over to Russell O’Connor’s colour library, and generally helping out with this release.
January 31, 2009 at 9:34 pm |
The patches you made after I left look really good. I’m sorry I didn’t get that colour thing working as best it could.
But the path work — and that dragon! — really cool. I’ll see what I can do about working up some projects that use the new features now.
February 1, 2009 at 12:21 am |
Dougal: hey, no worries. I don’t think I’ve quite got it working as best it could, either. =) You did some good work, and I’m grateful!
Projects that use the new features would be great! We need some cool projects to drive development of more new features. I have some ideas for one or two of my own, as well.
February 1, 2009 at 8:24 am |
[...] afternoon version 0.2 of Diagrams was released to an expectant and adoring public. I had a small hand in getting it through the door, [...]
February 2, 2009 at 8:36 am |
Hi Brent,
Diagrams looks great but so far no go.
Any chance of a fix for cabal install cairo -any problem?
It’s needed for formlets.
Cheers
Jim
February 2, 2009 at 8:57 am |
Hi Jim,
Unfortunately, the cairo package has not (yet) been cabalized, for, I’m told, various technical reasons. As explained in the installation instructions, you have to manually download and install gtk2hs (which includes the cairo library). A bit of a pain, but that’s the way it is for now. Hopefully at some point in the future the cairo bindings will be split out into their own package and cabalized.
February 18, 2009 at 5:01 pm |
[...] Metapost using Haskell Jump to Comments Brent Yorgey has released a Haskell EDSL for creating diagrams. Here is my first impression of the library, comparing it with [...]