Copyright | (c) 2011 Michael Sloan |
---|---|

License | BSD-style (see LICENSE) |

Maintainer | Michael Sloan <mgsloan at gmail> |

Safe Haskell | None |

Language | Haskell2010 |

Stateful domain specific language for diagram paths, modelled after the classic "turtle" graphics language.

- type Turtle n = TurtleT n Identity
- type TurtleT n = StateT (TurtleState n)
- runTurtle :: (Floating n, Ord n) => Turtle n a -> TurtleState n
- runTurtleT :: (OrderedField n, Monad m) => TurtleT n m a -> m (TurtleState n)
- drawTurtle :: (Renderable (Path V2 n) b, TypeableFloat n) => Turtle n a -> QDiagram b V2 n Any
- drawTurtleT :: (Monad m, Functor m, Renderable (Path V2 n) b, TypeableFloat n) => TurtleT n m a -> m (QDiagram b V2 n Any)
- sketchTurtle :: (Floating n, Ord n) => Turtle n a -> Path V2 n
- sketchTurtleT :: (Functor m, Monad m, Floating n, Ord n) => TurtleT n m a -> m (Path V2 n)
- forward :: (OrderedField n, Monad m) => n -> TurtleT n m ()
- backward :: (OrderedField n, Monad m) => n -> TurtleT n m ()
- left :: (OrderedField n, Monad m) => n -> TurtleT n m ()
- right :: (OrderedField n, Monad m) => n -> TurtleT n m ()
- heading :: (OrderedField n, Monad m) => TurtleT n m n
- setHeading :: (OrderedField n, Monad m) => n -> TurtleT n m ()
- towards :: (Monad m, RealFloat n, Ord n) => P2 n -> TurtleT n m ()
- isDown :: Monad m => TurtleT n m Bool
- pos :: Monad m => TurtleT n m (P2 n)
- setPos :: (OrderedField n, Monad m) => P2 n -> TurtleT n m ()
- setPenWidth :: (OrderedField n, Monad m) => n -> TurtleT n m ()
- setPenColor :: (OrderedField n, Monad m) => Colour Double -> TurtleT n m ()
- penUp :: (OrderedField n, Monad m) => TurtleT n m ()
- penDown :: (OrderedField n, Monad m) => TurtleT n m ()
- penHop :: (OrderedField n, Monad m) => TurtleT n m ()
- closeCurrent :: (OrderedField n, Monad m) => TurtleT n m ()

# Documentation

type TurtleT n = StateT (TurtleState n) Source

# Turtle control commands

runTurtle :: (Floating n, Ord n) => Turtle n a -> TurtleState n Source

Run the turtle, yielding the final turtle state.

runTurtleT :: (OrderedField n, Monad m) => TurtleT n m a -> m (TurtleState n) Source

A more general way to run the turtle. Returns a computation in the
underlying monad `m`

yielding the final turtle state.

drawTurtle :: (Renderable (Path V2 n) b, TypeableFloat n) => Turtle n a -> QDiagram b V2 n Any Source

Run the turtle, yielding a diagram.

drawTurtleT :: (Monad m, Functor m, Renderable (Path V2 n) b, TypeableFloat n) => TurtleT n m a -> m (QDiagram b V2 n Any) Source

A more general way to run the turtle. Returns a computation in
the underlying monad `m`

yielding the final diagram.

sketchTurtle :: (Floating n, Ord n) => Turtle n a -> Path V2 n Source

Run the turtle, ignoring any pen style commands and yielding a 2D path.

sketchTurtleT :: (Functor m, Monad m, Floating n, Ord n) => TurtleT n m a -> m (Path V2 n) Source

A more general way to run the turtle. Returns a computation in
the underlying monad `m`

, ignoring any pen style commands and
yielding a 2D path.

# Motion commands

forward :: (OrderedField n, Monad m) => n -> TurtleT n m () Source

Move the turtle forward, along the current heading.

backward :: (OrderedField n, Monad m) => n -> TurtleT n m () Source

Move the turtle backward, directly away from the current heading.

left :: (OrderedField n, Monad m) => n -> TurtleT n m () Source

Modify the current heading to the left by the specified angle in degrees.

right :: (OrderedField n, Monad m) => n -> TurtleT n m () Source

Modify the current heading to the right by the specified angle in degrees.

# State accessors / setters

heading :: (OrderedField n, Monad m) => TurtleT n m n Source

Get the current turtle angle, in degrees.

setHeading :: (OrderedField n, Monad m) => n -> TurtleT n m () Source

Set the current turtle angle, in degrees.

towards :: (Monad m, RealFloat n, Ord n) => P2 n -> TurtleT n m () Source

Sets the heading towards a given location.

isDown :: Monad m => TurtleT n m Bool Source

Queries whether the pen is currently drawing a path or not.

setPos :: (OrderedField n, Monad m) => P2 n -> TurtleT n m () Source

Set the current turtle X/Y position.

setPenWidth :: (OrderedField n, Monad m) => n -> TurtleT n m () Source

Sets the pen size

setPenColor :: (OrderedField n, Monad m) => Colour Double -> TurtleT n m () Source

Sets the pen color

# Drawing control

penUp :: (OrderedField n, Monad m) => TurtleT n m () Source

Ends the current path, and enters into "penUp" mode

penDown :: (OrderedField n, Monad m) => TurtleT n m () Source

Ends the current path, and enters into "penDown" mode

penHop :: (OrderedField n, Monad m) => TurtleT n m () Source

Start a new trail at current position

closeCurrent :: (OrderedField n, Monad m) => TurtleT n m () Source

Closes the current path , to the starting position of the current trail. Has no effect when the pen position is up.