This module implements an interpreter for the Piet programming language.
- interpret :: Program -> PietMonad ()
- interpretWhite :: Program -> PietMonad ()
- nonBlackSucc :: Program -> LabelInfo -> DirectionPointer -> CodelChooser -> Maybe (Int, Int, DirectionPointer, CodelChooser)
- succCoordinates :: LabelInfo -> DirectionPointer -> CodelChooser -> (Int, Int)
- colours2Command :: Lightness -> HueColour -> Lightness -> HueColour -> Int -> PietMonad ()
- colourDiff2Command :: Lightness -> HueColour -> Int -> PietMonad ()
Interpreter implementation
Helper functions
Movement
:: Program | Program |
-> LabelInfo | Current block |
-> DirectionPointer | DP |
-> CodelChooser | CC |
-> Maybe (Int, Int, DirectionPointer, CodelChooser) | Next coordinates, DP and CC (if available) |
Find coordinates and resulting DP/CC of the successing non-black block,
if it exists, Nothing
otherwise.
:: LabelInfo | Current label |
-> DirectionPointer | DP |
-> CodelChooser | CC |
-> (Int, Int) | Where to enter the next block |
Given a label, a DirectionPointer
and a CodelChooser
, this
function finds the coordinates of the next block to enter. These
coordinates are not guaranteed to be valid, they might be out of
range or point to a Black
or White
block.
Colour difference handling
:: Lightness |
|
-> HueColour |
|
-> Lightness |
|
-> HueColour |
|
-> Int | The size of the "from"-block |
-> PietMonad () | Resulting Piet operation |
Piet's commands are issued by a colour change, see
http://www.dangermouse.net/esoteric/piet.html. This function
takes two neighbouring colours and returns the resulting Piet
command, which is a function consuming (or more likely,
ignoring) an Int
(the size of the colour block that is being
left) and returning a
.
PietMonad
()
colourDiff2Command :: Lightness -> HueColour -> Int -> PietMonad ()Source
Converts a colour difference calculated by Language.Piet.Types.colourChange
and
lightnessChange
to a
, compare PietMonad
()colours2Command
.