helm-0.7.0: A functionally reactive game engine.

Safe HaskellNone

FRP.Helm.Graphics

Contents

Description

Contains all the data structures and functions for composing and rendering graphics.

Synopsis

Types

data Element Source

A data structure describing something that can be rendered to the screen. Elements are the most important structure in Helm. Games essentially feed the engine a stream of elements which are then rendered directly to the screen. The usual way to render art in a Helm game is to call off to the collage function, which essentially renders a collection of forms together.

Constructors

CollageElement Int Int (Maybe (Double, Double)) [Form] 
ImageElement (Int, Int) Int Int FilePath Bool 
TextElement Text 

Instances

Eq Element 
Show Element 

data FontWeight Source

A data structure describing the weight of a piece of font.

Instances

data FontStyle Source

A data structure describing the style of of a piece of font.

Instances

Enum FontStyle 
Eq FontStyle 
Ord FontStyle 
Read FontStyle 
Show FontStyle 

data Text Source

A data structure describing a piece of formatted text.

Constructors

Text 

Fields

textUTF8 :: String
 
textColor :: Color
 
textTypeface :: String
 
textHeight :: Double
 
textWeight :: FontWeight
 
textStyle :: FontStyle
 

Instances

Eq Text 
Show Text 

data Form Source

A data structure describing a form. A form is essentially a notion of a transformed graphic, whether it be an element or shape. See FormStyle for an insight into what sort of graphics can be wrapped in a form.

Constructors

Form 

Fields

formTheta :: Double
 
formScale :: Double
 
formX :: Double
 
formY :: Double
 
formStyle :: FormStyle
 

Instances

Eq Form 
Show Form 

data FormStyle Source

A data structure describing a few ways that graphics that can be wrapped in a form and hence transformed.

Instances

Eq FormStyle 
Show FormStyle 

data FillStyle Source

A data structure describing how a shape or path looks when filled.

Constructors

Solid Color 
Texture String 
Gradient Gradient 

Instances

Eq FillStyle 
Ord FillStyle 
Read FillStyle 
Show FillStyle 

data LineCap Source

A data structure describing the shape of the ends of a line.

Constructors

FlatCap 
RoundCap 
PaddedCap 

Instances

Enum LineCap 
Eq LineCap 
Ord LineCap 
Read LineCap 
Show LineCap 

data LineJoin Source

A data structure describing the shape of the join of a line, i.e. where separate line segments join. The Sharp variant takes an argument to limit the length of the join.

Constructors

SmoothJoin 
SharpJoin Double 
ClippedJoin 

Instances

Eq LineJoin 
Ord LineJoin 
Read LineJoin 
Show LineJoin 

data LineStyle Source

A data structure describing how a shape or path looks when stroked.

Constructors

LineStyle 

Fields

lineColor :: Color
 
lineWidth :: Double
 
lineCap :: LineCap
 
lineJoin :: LineJoin
 
lineDashing :: [Double]
 
lineDashOffset :: Double
 

Instances

Eq LineStyle 
Show LineStyle 

type Path = [(Double, Double)]Source

A data type made up a collection of points that form a path when joined.

data Shape Source

A data structure describing a some sort of graphically representable object, such as a polygon formed from a list of points or a rectangle.

Constructors

PolygonShape Path 
RectangleShape (Double, Double) 
ArcShape (Double, Double) Double Double Double (Double, Double) 

Instances

Eq Shape 
Ord Shape 
Read Shape 
Show Shape 

Elements

image :: Int -> Int -> FilePath -> ElementSource

Create an element from an image with a given width, height and image file path. If the image dimensions are not the same as given, then it will stretch/shrink to fit. Only PNG files are supported currently.

fittedImage :: Int -> Int -> FilePath -> ElementSource

Create an element from an image with a given width, height and image file path. If the image dimensions are not the same as given, then it will only use the relevant pixels (i.e. cut out the given dimensions instead of scaling). If the given dimensions are bigger than the actual image, than irrelevant pixels are ignored.

croppedImage :: (Int, Int) -> Int -> Int -> FilePath -> ElementSource

Create an element from an image by cropping it with a certain position, width, height and image file path. This can be used to divide a single image up into smaller ones.

collage :: Int -> Int -> [Form] -> ElementSource

Create an element from a collection of forms, with width and height arguments. All forms are centered and clipped within the supplied dimensions. It is generally used to directly render a collection of forms.

 collage 800 600 [move (100, 100) $ filled red $ square 100,
                  move (100, 100) $ outlined (solid white) $ circle 50]

centeredCollage :: Int -> Int -> [Form] -> ElementSource

Like collage, but it centers the forms within the supplied dimensions.

fixedCollage :: Int -> Int -> (Double, Double) -> [Form] -> ElementSource

Like centeredCollage, but it centers the forms around a specific point.

Styles & Forms

defaultLine :: LineStyleSource

Creates the default line style. By default, the line is black with a width of 1, flat caps and regular sharp joints.

solid :: Color -> LineStyleSource

Create a solid line style with a color.

dashed :: Color -> LineStyleSource

Create a dashed line style with a color.

dotted :: Color -> LineStyleSource

Create a dotted line style with a color.

filled :: Color -> Shape -> FormSource

Creates a form from a shape by filling it with a specific color.

textured :: String -> Shape -> FormSource

Creates a form from a shape with a tiled texture and image file path.

gradient :: Gradient -> Shape -> FormSource

Creates a form from a shape filled with a gradient.

outlined :: LineStyle -> Shape -> FormSource

Creates a form from a shape by outlining it with a specific line style.

traced :: LineStyle -> Path -> FormSource

Creates a form from a path by tracing it with a specific line style.

sprite :: Int -> Int -> (Int, Int) -> FilePath -> FormSource

Creates a form from a image file path with additional position, width and height arguments. Allows you to splice smaller parts from a single image.

toForm :: Element -> FormSource

Creates a form from an element.

blank :: FormSource

Creates a empty form, useful for having forms rendered only at some state.

Grouping

group :: [Form] -> FormSource

Groups a collection of forms into a single one.

groupTransform :: Matrix -> [Form] -> FormSource

Groups a collection of forms into a single one, also applying a matrix transformation.

Transforming

rotate :: Double -> Form -> FormSource

Rotates a form by an amount (in radians).

scale :: Double -> Form -> FormSource

Scales a form by an amount, e.g. scaling by 2.0 will double the size.

move :: (Double, Double) -> Form -> FormSource

Moves a form relative to its current position.

moveX :: Double -> Form -> FormSource

Moves a form's x-coordinate relative to its current position.

moveY :: Double -> Form -> FormSource

Moves a form's y-coordinate relative to its current position.

Paths

path :: [(Double, Double)] -> PathSource

Creates a path for a collection of points.

segment :: (Double, Double) -> (Double, Double) -> PathSource

Creates a path from a line segment, i.e. a start and end point.

Shapes

polygon :: Path -> ShapeSource

Creates a shape from a path (a list of points).

rect :: Double -> Double -> ShapeSource

Creates a rectangular shape with a width and height.

square :: Double -> ShapeSource

Creates a square shape with a side length.

oval :: Double -> Double -> ShapeSource

Creates an oval shape with a width and height.

circle :: Double -> ShapeSource

Creates a circle shape with a radius.

ngon :: Int -> Double -> ShapeSource

Creates a generic n-sided polygon (e.g. octagon, pentagon, etc) with an amount of sides and radius.