Difference between revisions of "Diagrams"

From HaskellWiki
Jump to navigation Jump to search
Line 73: Line 73:
 
* animations/pages/frames
 
* animations/pages/frames
   
=== Data structures ===
 
<haskell>
 
data Figure = Figure {
 
fill :: Fill
 
, shape :: Shape
 
, stroke :: Stroke
 
}
 
 
data Fill = Fill {
 
fillPaint :: Paint,
 
}
 
 
data Stroke = Stroke {
 
strokePaint :: Paint,
 
, lineWidth :: Double,
 
, dashPattern :: DashPattern
 
, lineCap :: LineCap
 
, lineJoin :: LineJoin
 
, miterLimit :: Double
 
} deriving(Eq, Show)
 
 
data Paint =
 
SolidColor
 
| Pattern
 
| Gradient
 
deriving(Eq, Show)
 
 
data LineCap =
 
LineCapButt
 
| LineCapRound
 
| LineCapSquare
 
deriving(Eq, Show)
 
 
data LineJoin =
 
LineJoinMiter
 
| LineJoinRound
 
| LineJoinBevel
 
deriving(Eq, Show)
 
 
data Shape =
 
Path
 
| Primitive
 
| Text
 
deriving(Eq, Show)
 
 
data Path = Path {
 
segments :: [Segment]
 
}
 
deriving(Eq, Show)
 
 
data Segment =
 
Move Point
 
| Line {
 
a :: Point
 
, b :: Point
 
}
 
| HorizontalLine {
 
a :: Point
 
, w :: Double
 
}
 
| VerticalLine {
 
a :: Point
 
, h :: Double
 
}
 
| QuadraticBezier Point Point Point
 
| CubicBezier Point Point Point Point
 
deriving(Eq, Show)
 
 
data Point =
 
Node2d Double Double
 
| Node3d Double Double Double
 
deriving(Eq, Show)
 
 
data Primitive =
 
Circle
 
| Ellipse
 
| Rectangle
 
| RegularPolygon
 
| Square
 
| Star
 
deriving(Eq, Show)
 
 
class PathLike a =
 
convertToPath :: a -> Path
 
</haskell>
 
   
   

Revision as of 08:50, 7 December 2009

The diagrams library provides an embedded domain-specific language (EDSL) for creating simple pictures and diagrams in Haskell


Rewrite

Core DSL

Style

Do we either want

yellowCircle x y radius = yellowFill $ circleShape x y radius

or

drawYellowCircle x y radius = do $

   setFill yellow
   drawCircle x y radius

?

The first version allows better reuse and functional composition.

Elements

  • graphical primitives
    • path
      • boundingBox
      • moveTo, lineTo, cubic bezier, quadratic bezier, arcTo
    • text
      • boundingBox
      • convertToPath
    • circle
      • boundingBox
      • convertToPath
    • ellipse
      • boundingBox
      • convertToPath
    • rectangle
      • boundingBox
      • convertToPath
    • polygon
      • boundingBox
      • convertToPath
    • polyline
      • boundingBox
      • convertToPath
  • graphical attributes
    • fill
      • paint
        • solid color, gradient, pattern
      • fill rule
        • evenOdd, nonZero
    • stroke
      • paint
        • solid color, gradient, pattern
      • width
      • line cap
      • line join
      • miter limit
      • dash
        • offset
        • array
    • marker symbols
    • effects
      • shadow, blur, turbulence
  • constraint solving
  • animations/pages/frames


Modules/Extensions

Paths

  • inset, outset
  • boolean operations
  • morphing
  • approximation (autotrace)

See

Shapes and symbols

Input/Output

Many Haskell graphic libraries are tied to a specific rendering backend (Cairo, OpenGL, libGD etc) which makes collaboration and reuse of code and data structures very hard or impossible.

Also some dependencies are hard to fulfill. Cairo is very difficult to install on Mac OS 10.6. If you just need to generate PDF diagrams, you could choose the pure HPDF library where e.g. Hieroglyph can not be installed because of its Cairo dependence.

Output

  • interactive drawing via Cairo
  • PDF export via pure HPDF
  • EPS export
  • SWF export
  • LaTeX export
  • exotic backends

Input

  • pure Haskell PNG import via pngload
  • pure Haskell SVG import

Inspiration

Related non-Haskell projects

Food for thought