nanovg-simple-0.4.0.0: Simple interface to rendering with NanoVG

Safe HaskellNone
LanguageHaskell2010

Graphics.NanoVG.Picture

Contents

Description

The module was originally inspired by gloss Picture data type.

It allows you to define simple pieces, combine and move/rotate/scale them to produce the final image.

Example of composite picture (filled circle inside stroked one, both moved to the side by 50 pixels):

translateP 50 0 $ pictures
  [ fill (NVG.Color 1 1 1 1) $ circle (10, 10) 10
  , stroke (NVG.Color 1 1 1 1) $ circle (10, 10) 15
  ]
Synopsis

Shapes

newtype Shape Source #

Shape of a future picture fragment, to be filled or stroked later. Action should define set of paths for the passed Context.

Constructors

Shape 

Fields

Helper type aliases

type Radius = Float Source #

Radius of a circle or an arc.

type Point = (Float, Float) Source #

Point on 2D plane.

type Center = Point Source #

Point representing center of circle, arc, rotation or scale.

type Angle = Float Source #

Angle of rotation, arc, etc.

Predefined Constructors

circle :: Center -> Radius -> Shape Source #

Make circular shape.

line :: Point -> Point -> Shape Source #

Make line shape.

rectangle :: Point -> Point -> Shape Source #

Make rectangular shape given two (opposite) corners positions.

arc :: Center -> Radius -> Angle -> Angle -> Shape Source #

Make arc shape with given center and going counter-clockwise from first angle to the second.

shapes :: [Shape] -> Shape Source #

Combine multiple shapes together.

translateS :: Float -> Float -> Shape -> Shape Source #

Translate shape by given x and y offsets.

rotateS :: Center -> Angle -> Shape -> Shape Source #

Rotate shape around given point by given angle.

scaleS :: Center -> Angle -> Float -> Shape -> Shape Source #

Scale shape from given point in given direction. This is affine transformation

scaleS' :: Center -> Float -> Shape -> Shape Source #

Scale shape from given point by given factor in every direction.

scaleSx :: Center -> Float -> Shape -> Shape Source #

Scale shape from given point in positive X direction by given factor.

scaleSy :: Center -> Float -> Shape -> Shape Source #

Scale shape from given point in positive Y direction by given factor.

hole :: Shape -> Shape Source #

Turns shape into a hole which can then be combined with other (solid) shape. E.g.

fill (Color 1 0 0 1) $ shapes [circle (0, 0) 40, hole $ circle (0, 0) 30]

can be used to create a ring of width 10.

Pictures

data Picture Source #

Picture represent collection of filled/stroked shapes ready to be rendered

mapShape :: (Shape -> Shape) -> Picture -> Picture Source #

Modify shape(s) the picture was based off.

Contstructors

Pictures are generally constructed by filling or stroking shape or by transforming exising picture.

stroke :: Color -> Shape -> Picture Source #

Stroke the shape to create a picture.

fill :: Color -> Shape -> Picture Source #

Fill the shape to create a picture.

pictures :: [Picture] -> Picture Source #

Combine multiple pictures together.

translateP :: Float -> Float -> Picture -> Picture Source #

Translate the picture by given x and y offsets.

rotateP :: Center -> Angle -> Picture -> Picture Source #

Rotate the picture around given point for given angle.

scaleP :: Center -> Angle -> Float -> Picture -> Picture Source #

Scale picture from given point in given direction. This is affine transformation

scaleP' :: Center -> Float -> Picture -> Picture Source #

Scale picture from given point by given factor in every direction.

scalePx :: Center -> Float -> Picture -> Picture Source #

Scale picture from given point in positive X direction by given factor.

scalePy :: Center -> Float -> Picture -> Picture Source #

Scale picture from given point in positive Y direction by given factor.

Rendering

render :: Context -> Picture -> IO () Source #

Render picture with given NanoVG context.

Rendering as Window

asWindow :: IO Picture -> Window () Source #

Create Window which constantly queries and renders received picture.