piet-0.1: A Piet interpreter

Language.Piet.Types

Contents

Description

A module providing a couple of Piet-specific types and simple associated functions needed throughout the library.

Synopsis

Piet Interpreter

Direction Pointer and Codel Chooser

addCoordinatesSource

Arguments

:: DirectionPointer

Direction to move to

-> Int

x-coordinate

-> Int

y-coordinate

-> (Int, Int)

New x-/y-coordinates

Move coordinates by one in the direction of the DirectionPointer.

rotate :: Int -> DirectionPointer -> DirectionPointerSource

Rotate a DirectionPointer clockwise (counter clockwise if the Int is negative) a given number of times.

toggle :: Int -> CodelChooser -> CodelChooserSource

Toggle a CodelChooser a given number of times.

Piet's type system

data PietType Source

Piet types. Relevant to distinguish in-/output strategies.

Constructors

PietNumber 
PietChar 

Runtime program representation

data Program Source

Runtime program representation.

Constructors

Program 

Fields

image :: Image Colour

Original image

mask :: Image LabelKey

Labelled image

info :: IntMap LabelInfo

Information about the labels

isBlocked :: Int -> Int -> Program -> BoolSource

Returns if a given codel in a program is blocked in the Piet sense (which is the case when it is out of the image's range or Black).

Colour system

data Colour Source

The colours that make up a Piet program text.

Constructors

Black 
White 
Hue !Lightness !HueColour 

rgba2ColourSource

Arguments

:: Num w 
=> w

red

-> w

green

-> w

blue

-> w

alpha

-> Colour 

Converts red/green/blue/alpha values to a Colour. The alpha channel is ignored for now, but may be used in future implementations or dialects, so please use this function instead of rgb2Colour whenever an alpha channel is available.

rgb2ColourSource

Arguments

:: Num w 
=> w

red

-> w

green

-> w

blue

-> Colour 

Converts red/green/blue values to a Colour. If the supplied arguments do not form a proper Piet Colour, White is returned.

data HueColour Source

Piet colours in the hue cycle.

Constructors

Red 
Yellow 
Green 
Cyan 
Blue 
Magenta 

hueChange :: HueColour -> HueColour -> HueColourSource

Hue difference between two HueColours. Red means no change, Yellow one step and so forth.

data Lightness Source

Hue lightness values supported by Piet.

Constructors

Light 
Normal 
Dark 

lightnessChange :: Lightness -> Lightness -> LightnessSource

Lightness difference between Piet lightness values. Light represents no change, Normal one step darker and Dark two steps darker.

Images

data Image a Source

An image. Its coordinates will be (0, 0) .. (width-1, height-1)

Instances

Functor Image 
Eq a => Eq (Image a) 
Ord a => Ord (Image a) 
Show a => Show (Image a) 

imgWidth :: Image a -> IntSource

Width of an Image in pixels.

imgHeight :: Image a -> IntSource

Height of an Image in pixels.

imgInRangeSource

Arguments

:: Int

x-coordinate

-> Int

y-coordinate

-> Image a

An Image

-> Bool

If (x, y) is within the Image

Find out, if the given coordinates are within the Image borders (which are (0, 0) .. (width-1, height-1)).

imgNewSource

Arguments

:: Int

Width

-> Int

Height

-> [((Int, Int), a)]

Coordinate-value list

-> Image a 

Build a new image.

imgPixelSource

Arguments

:: Int

x-coordinate

-> Int

y-coordinate

-> Image a 
-> a 

Access a pixel at given x/y-coordinates.

imgSetPixel :: Int -> Int -> a -> Image a -> Image aSource

Set a pixel at given x/y-coordinates.

type LabelKey = IntSource

We'll just use Ints to identifiy labels.

data LabelInfo Source

Stores compiler-relevant information about a label. This type implements an instance of Monoid to merge labels.

Constructors

EmptyInfo

The empty label

LabelInfo

Label with a size and four borders

Fields

_labelSize :: !Int

Number of pixels

labelTop :: !LabelBorder

Top border

labelLeft :: !LabelBorder

left border

labelBottom :: !LabelBorder

Bottom border

labelRight :: !LabelBorder

Right border

labelSize :: LabelInfo -> IntSource

Number of pixels in a label. This function is defined for all constructors of LabelInfo so, in contrast to _labelSize, it won't fail on EmptyInfo .

addPixel :: Int -> Int -> LabelInfo -> LabelInfoSource

Add a pixel to a LabelInfo.

data LabelBorder Source

Holds information of a label (coloured area) relevant for the Piet language, i. e. information about where the program flow will be directed regarding a Direction Pointer.

Holds a border position (e. g. an x-coordinate) and the minimum or maximum associated "other" coordinates (e. g. y-coordinates).

Constructors

LabelBorder 

Fields

borderCoord :: !Int

Where the border is located

borderMin :: !Int

Minimum "other" coordinate of the border

borderMax :: !Int

Maximum "other" coordinate of the border