Diagrams 0.2 release

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

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.

About Brent

Assistant Professor of Computer Science at Hendrix College. Functional programmer, mathematician, teacher, pianist, follower of Jesus.
This entry was posted in haskell, projects and tagged , , , , . Bookmark the permalink.

6 Responses to Diagrams 0.2 release

  1. Dougal says:

    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.

  2. Brent says:

    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.

  3. Pingback: Looking Out To Sea » In support of a release announcement (or, Pimp your diagrams package)

  4. Jim Stuttard says:

    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.

  5. Brent says:

    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.

  6. Pingback: Imitating Metapost using Haskell « Random Determinism

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.