generative-art-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Draw

Description

Cairo drawing backend.

Synopsis

SVG and PNG file handling

render Source #

Arguments

:: FilePath 
-> Int

Height (px)

-> Int

Width (px)

-> Render () 
-> IO () 

Renders the drawing as PNG or SVG, depending on the file extension.

data CoordinateSystem Source #

Argument to coordinateSystem to pick zero location and axis direction.

Constructors

CairoStandard_ZeroTopLeft_XRight_YDown

Left-handed coordinate system. Standard Cairo/computer graphics coordinates. Zero is on the top left, and the Y axis points downwards. Even though this is common in computer graphics, working geometrically with a left-handed coordinate system can be a bit awkward and surprising.

(image code)

Expand
>>> :{
haddockRender "Draw/coordinate_system_cairo_standard.svg" 200 160 $ \_ -> do
    coordinateSystem CairoStandard_ZeroTopLeft_XRight_YDown
    cairoScope $ do
        sketch (Arrow (angledLine (Vec2 10 10) (deg 0) 180) def)
        sketch (Arrow (angledLine (Vec2 10 10) (deg 90) 140) def)
        stroke
    cairoScope $ do
        C.translate 10 10
        setColor (mma 1)
        let radius = 40
        arc 0 0 radius 0 (pi/2)
        sketch (Arrow (lineReverse (angledLine (Vec2 0 radius) (deg (-7)) 10))
                      def {_arrowDrawBody=False})
        stroke
:}
Generated file: size 2KB, crc32: 0x22a87e3e
MathStandard_ZeroBottomLeft_XRight_YUp Double

Right-handed coordinate system. Standard math coordinates, with zero on the bottom left. Needs the image’s height as arguments for technical reasons.

(image code)

Expand
>>> :{
haddockRender "Draw/coordinate_system_math_standard.svg" 200 160 $ \_ -> do
    coordinateSystem (MathStandard_ZeroBottomLeft_XRight_YUp 160)
    cairoScope $ do
        sketch (Arrow (angledLine (Vec2 10 10) (deg 0) 180) def)
        sketch (Arrow (angledLine (Vec2 10 10) (deg 90) 140) def)
        stroke
    cairoScope $ do
        C.translate 10 10
        setColor (mma 1)
        let radius = 40
        arc 0 0 radius 0 (pi/2)
        sketch (Arrow (lineReverse (angledLine (Vec2 0 radius) (deg (-7)) 10))
                      def {_arrowDrawBody=False})
        stroke
:}
Generated file: size 3KB, crc32: 0xd33a20ee
MathStandard_ZeroCenter_XRight_YUp Double Double

Right-handed coordinate system. Standard math coordinates, with zero in the center. Needs the image’s width and height as arguments for technical reasons.

(image code)

Expand
>>> :{
haddockRender "Draw/coordinate_system_math_standard_centered.svg" 200 160 $ \(Vec2 w h) -> do
    coordinateSystem (MathStandard_ZeroCenter_XRight_YUp w h)
    cairoScope $ do
        sketch (Arrow (centerLine (Line (Vec2 0 0) (Vec2 (w-20) 0))) def)
        sketch (Arrow (centerLine (Line (Vec2 0 0) (Vec2 0 (h-20)))) def)
        stroke
    cairoScope $ do
        setColor (mma 1)
        let radius = 40
        arc 0 0 radius 0 (pi/2)
        sketch (Arrow (lineReverse (angledLine (Vec2 0 radius) (deg (-5)) 10))
                      def {_arrowDrawBody=False})
        stroke
:}
Generated file: size 3KB, crc32: 0xe6e10f11

coordinateSystem :: CoordinateSystem -> Render () Source #

Choose a coordinate system.

haddockRender Source #

Arguments

:: FilePath 
-> Int

Image width (px)

-> Int

Image height (px)

-> (Vec2 -> Render ())

The width/height of the image is passed as Double-based Vec2s to the rendering function for convenience. This makes it easier to write images that scale with changes in the width/height parameters.

-> IO () 

Render pictures for Haddock with doctests. Nomenclature: the FilePath for Foo.Bar.Baz is Foo/Bar/Baz/pic_name.svg.

Prints status information about the generated file so that doctests fail when the file contents change. Inspect the new output and update the output if the result is OK.

Drawing presets

moveToVec :: Vec2 -> Render () Source #

Vec2-friendly version of Cairo’s moveTo.

lineToVec :: Vec2 -> Render () Source #

Vec2-friendly version of Cairo’s lineTo.

class Sketch a where Source #

Sketch a shape that can then be made visible by drawing functions such as stroke or fill.

Methods

sketch :: a -> Render () Source #

Instances

Instances details
Sketch Arrow Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Arrow.svg" 150 100 $ \_ -> do
    C.setLineWidth 2
    sketch (Arrow (Line (Vec2 10 10) (Vec2 140 90)) def)
    stroke
:}
Generated file: size 2KB, crc32: 0x2c724862
Instance details

Defined in Draw

Methods

sketch :: Arrow -> Render () Source #

Sketch Cross Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Cross.svg" 90 40 $ \_ -> do
    C.setLineWidth 2
    sketch (Cross  (Vec2 20 20) 15) >> stroke
    sketch (Cross  (Vec2 60 20) 15) >> stroke
    sketch (Circle (Vec2 60 20) 15) >> stroke
:}
Generated file: size 2KB, crc32: 0xe2cb8567
Instance details

Defined in Draw

Methods

sketch :: Cross -> Render () Source #

Sketch Ray Source # 
Instance details

Defined in Geometry.Algorithms.Delaunay.Internal.Delaunator.Api

Methods

sketch :: Ray -> Render () Source #

Sketch VoronoiPolygon Source # 
Instance details

Defined in Geometry.Algorithms.Delaunay.Internal.Delaunator.Api

Methods

sketch :: VoronoiPolygon -> Render () Source #

Sketch Bezier Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Bezier.svg" 150 100 $ \_ -> do
    C.setLineWidth 2
    sketch (Bezier (Vec2 10 10) (Vec2 50 200) (Vec2 100 (-50)) (Vec2 140 90))
    stroke
:}
Generated file: size 2KB, crc32: 0xe17dab02
Instance details

Defined in Draw

Methods

sketch :: Bezier -> Render () Source #

Sketch BoundingBox Source #

Sketches a rectangle with a diagonal cross through it. Useful for debugging.

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_BoundingBox.svg" 100 100 $ \_ -> do
    let geometry = [Circle (Vec2 30 30) 25, Circle (Vec2 60 60) 35]
    for_ geometry $ \x -> cairoScope (sketch x >> setColor (mma 1) >> setDash [4,6] 0 >> stroke)
    sketch (boundingBox geometry)
    stroke
:}
Generated file: size 3KB, crc32: 0xfed2c044
Instance details

Defined in Draw

Methods

sketch :: BoundingBox -> Render () Source #

Sketch Circle Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Circle.svg" 200 200 $ \_ -> do
    sketch (Circle (Vec2 100 100) 90)
    stroke
:}
Generated file: size 2KB, crc32: 0x565193fd
Instance details

Defined in Draw

Methods

sketch :: Circle -> Render () Source #

Sketch Ellipse Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Ellipse.svg" 150 100 $ \_ -> do
    C.setLineWidth 2
    sketch (G.transform (G.translate (Vec2 75 50) <> G.rotate (deg 20) <> G.scale' 1.4 0.9)
                        (toEllipse (Circle zero 45)))
    stroke
:}
Generated file: size 2KB, crc32: 0x25bae2ef
Instance details

Defined in Draw

Methods

sketch :: Ellipse -> Render () Source #

Sketch Line Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Line.svg" 150 100 $ \_ -> do
    C.setLineWidth 2
    sketch (Line (Vec2 10 10) (Vec2 140 90))
    stroke
:}
Generated file: size 2KB, crc32: 0x9287e4a8
Instance details

Defined in Draw

Methods

sketch :: Line -> Render () Source #

Sketch Polygon Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Polygon.svg" 100 100 $ \_ -> do
    C.setLineWidth 2
    sketch (Polygon [Vec2 20 10, Vec2 10 80, Vec2 45 45, Vec2 60 90, Vec2 90 30])
    stroke
:}
Generated file: size 2KB, crc32: 0x7f620554
Instance details

Defined in Draw

Methods

sketch :: Polygon -> Render () Source #

Sketch Polyline Source #

Polyline, i.e. a sequence of lines given by their joints.

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Sequential_Vec2.svg" 150 100 $ \_ -> do
    C.setLineWidth 2
    sketch (Polyline [Vec2 10 10, Vec2 90 90, Vec2 120 10, Vec2 140 50])
    stroke
:}
Generated file: size 2KB, crc32: 0x5d5a0158
Instance details

Defined in Draw

Methods

sketch :: Polyline -> Render () Source #

Sketch Transformation Source #

Draw a \(100\times 100\) square with its corner at zero and transformed with the Transformation, sometimes useful for debugging.

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Transformation.svg" 300 200 $ \_ -> do
    C.setLineWidth 2
    setColor (mma 0) >> sketch (G.translate (Vec2 20 20)) >> stroke
    setColor (mma 1) >> sketch (G.translate (Vec2 110 50) <> G.rotate (deg 30)) >> stroke
    setColor (mma 2) >> sketch (G.shear 0.5 0.2 <> G.translate (Vec2 140 0)) >> stroke
:}
Generated file: size 4KB, crc32: 0x1f4ae5da
Instance details

Defined in Draw

Methods

sketch :: Transformation -> Render () Source #

Sequential f => Sketch (PolyBezier f) Source #

Sketch a continuous curve consisting of multiple Bezier segments. The end of each segment is assumed to be the start of the next one.

Instance details

Defined in Draw

Methods

sketch :: PolyBezier f -> Render () Source #

Sketch a => Sketch (Maybe a) Source # 
Instance details

Defined in Draw

Methods

sketch :: Maybe a -> Render () Source #

Sketch a => Sketch [a] Source # 
Instance details

Defined in Draw

Methods

sketch :: [a] -> Render () Source #

(Sketch a, Sketch b) => Sketch (Either a b) Source # 
Instance details

Defined in Draw

Methods

sketch :: Either a b -> Render () Source #

(Sketch a, Sketch b) => Sketch (a, b) Source # 
Instance details

Defined in Draw

Methods

sketch :: (a, b) -> Render () Source #

(Sketch a, Sketch b, Sketch c) => Sketch (a, b, c) Source # 
Instance details

Defined in Draw

Methods

sketch :: (a, b, c) -> Render () Source #

(Sketch a, Sketch b, Sketch c, Sketch d) => Sketch (a, b, c, d) Source # 
Instance details

Defined in Draw

Methods

sketch :: (a, b, c, d) -> Render () Source #

(Sketch a, Sketch b, Sketch c, Sketch d, Sketch e) => Sketch (a, b, c, d, e) Source # 
Instance details

Defined in Draw

Methods

sketch :: (a, b, c, d, e) -> Render () Source #

data Arrow Source #

For sketching arrows.

Constructors

Arrow !Line !ArrowSpec 

Instances

Instances details
Show Arrow Source # 
Instance details

Defined in Draw

Methods

showsPrec :: Int -> Arrow -> ShowS #

show :: Arrow -> String #

showList :: [Arrow] -> ShowS #

Sketch Arrow Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Arrow.svg" 150 100 $ \_ -> do
    C.setLineWidth 2
    sketch (Arrow (Line (Vec2 10 10) (Vec2 140 90)) def)
    stroke
:}
Generated file: size 2KB, crc32: 0x2c724862
Instance details

Defined in Draw

Methods

sketch :: Arrow -> Render () Source #

Eq Arrow Source # 
Instance details

Defined in Draw

Methods

(==) :: Arrow -> Arrow -> Bool #

(/=) :: Arrow -> Arrow -> Bool #

data ArrowSpec Source #

Constructors

ArrowSpec 

Fields

Instances

Instances details
Show ArrowSpec Source # 
Instance details

Defined in Draw

Default ArrowSpec Source # 
Instance details

Defined in Draw

Methods

def :: ArrowSpec

Eq ArrowSpec Source # 
Instance details

Defined in Draw

data Circle Source #

Circles are not an instance of Transform, because e.g. shearing a circle yields an Ellipse. To transform circles, convert them to an ellipse first with toEllipse.

Constructors

Circle 

Instances

Instances details
Show Circle Source # 
Instance details

Defined in Geometry.Core

Default Circle Source #

Unit circle

Instance details

Defined in Geometry.Core

Methods

def :: Circle

NFData Circle Source # 
Instance details

Defined in Geometry.Core

Methods

rnf :: Circle -> () #

Sketch Circle Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Circle.svg" 200 200 $ \_ -> do
    sketch (Circle (Vec2 100 100) 90)
    stroke
:}
Generated file: size 2KB, crc32: 0x565193fd
Instance details

Defined in Draw

Methods

sketch :: Circle -> Render () Source #

Plotting Circle Source # 
Instance details

Defined in Draw.Plotting

Methods

plot :: Circle -> Plot () Source #

HasBoundingBox Circle Source #

(image code)

Expand
>>> :{
haddockRender "Geometry/Core/bounding_box_circle.svg" 150 150 $ \_ -> do
    let circle = Circle (Vec2 75 75) 65
    cairoScope $ do
        setColor (mma 1)
        C.setDash [1.5,3] 0
        sketch (boundingBox circle)
        C.stroke
    cairoScope $ do
        C.setLineWidth 2
        sketch circle
        C.stroke
:}
Generated file: size 2KB, crc32: 0x58f8a8af
Instance details

Defined in Geometry.Core

Eq Circle Source # 
Instance details

Defined in Geometry.Core

Methods

(==) :: Circle -> Circle -> Bool #

(/=) :: Circle -> Circle -> Bool #

Ord Circle Source # 
Instance details

Defined in Geometry.Core

data Cross Source #

sketch a cross like ×. Sometimes useful to decorate a line with for e.g. strikethrough effects, or to contrast the o in tic tac toe.

When drawn with the same radius, it combines to ⨂ with a Circle.

Constructors

Cross 

Instances

Instances details
Show Cross Source # 
Instance details

Defined in Draw

Methods

showsPrec :: Int -> Cross -> ShowS #

show :: Cross -> String #

showList :: [Cross] -> ShowS #

Sketch Cross Source #

(image code)

Expand
>>> :{
haddockRender "Draw/instance_Sketch_Cross.svg" 90 40 $ \_ -> do
    C.setLineWidth 2
    sketch (Cross  (Vec2 20 20) 15) >> stroke
    sketch (Cross  (Vec2 60 20) 15) >> stroke
    sketch (Circle (Vec2 60 20) 15) >> stroke
:}
Generated file: size 2KB, crc32: 0xe2cb8567
Instance details

Defined in Draw

Methods

sketch :: Cross -> Render () Source #

Eq Cross Source # 
Instance details

Defined in Draw

Methods

(==) :: Cross -> Cross -> Bool #

(/=) :: Cross -> Cross -> Bool #

Ord Cross Source # 
Instance details

Defined in Draw

Methods

compare :: Cross -> Cross -> Ordering #

(<) :: Cross -> Cross -> Bool #

(<=) :: Cross -> Cross -> Bool #

(>) :: Cross -> Cross -> Bool #

(>=) :: Cross -> Cross -> Bool #

max :: Cross -> Cross -> Cross #

min :: Cross -> Cross -> Cross #

newtype PolyBezier f Source #

Constructors

PolyBezier (f Bezier) 

Instances

Instances details
Sequential f => Sketch (PolyBezier f) Source #

Sketch a continuous curve consisting of multiple Bezier segments. The end of each segment is assumed to be the start of the next one.

Instance details

Defined in Draw

Methods

sketch :: PolyBezier f -> Render () Source #

arcSketch Source #

Arguments

:: Vec2

Center

-> Double

Radius

-> Angle

Starting angle (absolute)

-> Angle

Ending angle (absolute)

-> Render () 

Sketch part of a circle.

arcSketchNegative Source #

Arguments

:: Vec2

Center

-> Double

Radius

-> Angle

Starting angle (absolute)

-> Angle

Ending angle (absolute)

-> Render () 

Sketch part of a circle.

Colors

data Colour a #

Instances

Instances details
AffineSpace Colour 
Instance details

Defined in Data.Colour.Internal

Methods

affineCombo :: Num a => [(a, Colour a)] -> Colour a -> Colour a #

ColourOps Colour 
Instance details

Defined in Data.Colour.Internal

Methods

over :: Num a => AlphaColour a -> Colour a -> Colour a #

darken :: Num a => a -> Colour a -> Colour a #

Num a => Monoid (Colour a) 
Instance details

Defined in Data.Colour.Internal

Methods

mempty :: Colour a #

mappend :: Colour a -> Colour a -> Colour a #

mconcat :: [Colour a] -> Colour a #

Num a => Semigroup (Colour a) 
Instance details

Defined in Data.Colour.Internal

Methods

(<>) :: Colour a -> Colour a -> Colour a #

sconcat :: NonEmpty (Colour a) -> Colour a #

stimes :: Integral b => b -> Colour a -> Colour a #

Real a => CairoColor (Colour a) Source # 
Instance details

Defined in Draw.Color

Methods

setColor :: Colour a -> Render () Source #

setColour :: Colour a -> Render () Source #

Eq a => Eq (Colour a) 
Instance details

Defined in Data.Colour.Internal

Methods

(==) :: Colour a -> Colour a -> Bool #

(/=) :: Colour a -> Colour a -> Bool #

type Color a = Colour a Source #

American English type synonym

data AlphaColour a #

Instances

Instances details
AffineSpace AlphaColour 
Instance details

Defined in Data.Colour.Internal

Methods

affineCombo :: Num a => [(a, AlphaColour a)] -> AlphaColour a -> AlphaColour a #

ColourOps AlphaColour 
Instance details

Defined in Data.Colour.Internal

Methods

over :: Num a => AlphaColour a -> AlphaColour a -> AlphaColour a #

darken :: Num a => a -> AlphaColour a -> AlphaColour a #

Num a => Monoid (AlphaColour a) 
Instance details

Defined in Data.Colour.Internal

Num a => Semigroup (AlphaColour a) 
Instance details

Defined in Data.Colour.Internal

(Real a, Floating a) => CairoColor (AlphaColour a) Source # 
Instance details

Defined in Draw.Color

Methods

setColor :: AlphaColour a -> Render () Source #

setColour :: AlphaColour a -> Render () Source #

Eq a => Eq (AlphaColour a) 
Instance details

Defined in Data.Colour.Internal

type AlphaColor a = AlphaColour a Source #

American English type synonym

class CairoColor color where Source #

Anything we can instruct Cairo to set its color to.

Minimal complete definition

Nothing

Methods

setColor :: color -> Render () Source #

>>> :{
haddockRender "Draw/Color/set_color.svg" 140 40 $ \_ -> do
    for_ (zip [0..] [30, 40 .. 150-30]) $ \(i, x) -> do
        setColor (mma i)
        sketch (Circle (Vec2 x 20) 10)
        C.fill
:}
Generated file: size 4KB, crc32: 0xe0e16234

setColour :: color -> Render () Source #

Instances

Instances details
(Real a, Floating a) => CairoColor (AlphaColour a) Source # 
Instance details

Defined in Draw.Color

Methods

setColor :: AlphaColour a -> Render () Source #

setColour :: AlphaColour a -> Render () Source #

Real a => CairoColor (Colour a) Source # 
Instance details

Defined in Draw.Color

Methods

setColor :: Colour a -> Render () Source #

setColour :: Colour a -> Render () Source #

module Draw.Color

Discrete color schemes

Discrete color schemes, taken from:

NameDomain
mma[0..∞)
accent[0..7]
dark2[0..7]
paired[0..11]
pastel1[0..8]
pastel2[0..7]
set1[0..8]
set2[0..7]
set3[0..11]

Continuous color schemes

Continuous color schemes, taken from:

NameDomainType
haskell[0..1]Monotone
magma[0..1]Monotone
inferno[0..1]Monotone
plasma[0..1]Monotone
viridis[0..1]Monotone
cividis[0..1]Monotone
turbo[0..1]Monotone
twilight[0..1]Cyclic
rocket[0..1]Monotone
mako[0..1]Monotone
flare[0..1]Monotone
crest[0..1]Monotone
vlag[0..1]Divisive
icefire[0..1]Divisive
orRd[0..1]Monotone
puBu[0..1]Monotone
buPu[0..1]Monotone
oranges[0..1]Monotone
buGn[0..1]Monotone
ylOrBr[0..1]Monotone
ylGn[0..1]Monotone
reds[0..1]Monotone
rdPu[0..1]Monotone
greens[0..1]Monotone
ylGnBu[0..1]Monotone
purples[0..1]Monotone
gnBu[0..1]Monotone
greys[0..1]Monotone
ylOrRd[0..1]Monotone
puRd[0..1]Monotone
blues[0..1]Monotone
puBuGn[0..1]Monotone
spectral[0..1]Divisive
rdYlGn[0..1]Divisive
rdBu[0..1]Divisive
piYG[0..1]Divisive
pRGn[0..1]Divisive
rdYlBu[0..1]Divisive
brBG[0..1]Divisive
rdGy[0..1]Divisive
puOr[0..1]Divisive

Temporary Cairo modifications

withOperator :: Operator -> Render a -> Render a Source #

Temporarily draw using a different composition operator, such as OperatorClear to delete part of an image.

cairoScope :: Render a -> Render a Source #

Open a new Cairo scope to allow local parameter changes. When the scope closes, the parameters are reset. Cairo documentation hides what actually is in the parameter state remarkably well; the state thus includes (source):

  • Drawing operator (withOperator)
  • Tolerance (setTolerance)
  • Antialiasing (setAntialias)
  • Line style (setLineWidth, setLineCap, setLineJoin, setMiterLimit, setDash)
  • Fill rule (setFillRule)
  • Font face, scaling, options
  • Clipping (clip)
  • Pattern (includes colors/setColor, gradients/withLinearPattern etc.)
  • Tranformation matrix (translate etc.)

For example, we can paint the first block with a wide style, the second one dashed, and afterwards fall back to the implicit defaults:

>>> :{
haddockRender "Draw/cairoScope.svg" 200 40 $ \_ -> do
    let line = Line (Vec2 10 0) (Vec2 190 0)
    cairoScope $ do
        C.translate 0 30
        setLineWidth 3
        setColor (mma 1)
        sketch line
        stroke
    cairoScope $ do
        C.translate 0 20
        setDash [5,3] 0
        setColor (mma 2)
        sketch line
        stroke
    C.translate 0 10
    sketch line
    stroke
:}
Generated file: size 2KB, crc32: 0x2d7bee90

grouped :: Render after -> Render a -> Render a Source #

Render something as a group, as in encapsulate it in pushGroup and popGroupToSource. This function semantically includes a call cairoScope.

grouped is commonly used to avoid a less transparent area when overlapping two transparent areas.

The naive way has the intersection of the two circles darker,

do
    setSourceRGBA 0 0 0 0.5
    sketch (Circle (Vec2 0 0) 10)
    fill
    sketch (Circle (Vec2 7 0) 10)
    fill

On the other hand this will have the combination of the entire combined shape drawn with 0.5 alpha:

grouped (paintWithAlpha 0.5) $ do
    setSourceRGBA 0 0 0 1
    sketch (Circle (Vec2 0 0) 10)
    fill
    sketch (Circle (Vec2 7 0) 10)
    fill

Orientation helpers

cartesianCoordinateSystem :: CartesianParams -> Render () Source #

Draw a caresian coordinate system in range (x,x') (y,y'). Very useful for prototyping.

(image code)

Expand

>>> :{ haddockRender "Draw/cartesianCoordinateSystem.svg" 320 220 $ _ -> cartesianCoordinateSystem def :} Generated file: size 21KB, crc32: 0xf43aac0c

data CartesianParams Source #

Constructors

CartesianParams 

Fields

radialCoordinateSystem :: PolarParams -> Render () Source #

Like cartesianCoordinateSystem, but with polar coordinates.

(image code)

Expand
>>> :{
haddockRender "Draw/radialCoordinateSystem.svg" 250 250 $ \_ -> do
    C.translate 50 50
    radialCoordinateSystem def
:}
Generated file: size 26KB, crc32: 0x9b68b36

data PolarParams Source #

Instances

Instances details
Show PolarParams Source # 
Instance details

Defined in Draw

Default PolarParams Source # 
Instance details

Defined in Draw

Methods

def :: PolarParams

Eq PolarParams Source # 
Instance details

Defined in Draw

Ord PolarParams Source # 
Instance details

Defined in Draw

Transformations

fromCairoMatrix :: Matrix -> Transformation Source #

Translate between Cairo and our matrix representation for transformations.

Cairo does its transformation in inverse: we transform the geometry, Cairo transforms the canvas. fromCairoMatrix and toCairoMatrix translate between the worlds, so that conceptually both of these yield the same output:

trafo :: Transformation

sketch (Transform trafo geometry)
--
transform (fromCairoMatrix trafo) >> sketch geometry

Note that Cairo’s transform does more than just moving around lines: it also scales other properties such as line width, so the pictures described above might have some differences.

Useful Cairo functions for working with this are

transform :: Matrix -> Render ()
setMatrix :: Matrix -> Render ()
getMatrix :: Render Matrix

toCairoMatrix :: Transformation -> Matrix Source #

See fromCairoMatrix’ documentation, of which toCairoMatrix is the inverse.

Text

module Draw.Text

Convenience

for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () #

for_ is traverse_ with its arguments flipped. For a version that doesn't ignore the results see for. This is forM_ generalised to Applicative actions.

for_ is just like forM_, but generalised to Applicative actions.

Examples

Expand

Basic usage:

>>> for_ [1..4] print
1
2
3
4