module Diagrams.TwoD.Path.Turtle
( Turtle, TurtleT
, runTurtle, runTurtleT
, drawTurtle, drawTurtleT
, sketchTurtle, sketchTurtleT
, forward, backward, left, right
, heading, setHeading, towards, isDown
, pos, setPos, setPenWidth, setPenColor
, penUp, penDown, penHop, closeCurrent
) where
import qualified Control.Lens as L
import Control.Monad (liftM)
import qualified Control.Monad.State as ST
import Diagrams.Prelude
import qualified Diagrams.TwoD.Path.Turtle.Internal as T
type TurtleT n = ST.StateT (T.TurtleState n)
type Turtle n = TurtleT n Identity
runTurtleT :: (OrderedField n, Monad m) => TurtleT n m a -> m (T.TurtleState n)
runTurtleT t = ST.execStateT t T.startTurtle
runTurtle :: (Floating n, Ord n) => Turtle n a -> T.TurtleState n
runTurtle = runIdentity . runTurtleT
drawTurtleT :: (Monad m, Renderable (Path V2 n) b, TypeableFloat n)
=> TurtleT n m a -> m (QDiagram b V2 n Any)
drawTurtleT = liftM T.getTurtleDiagram . runTurtleT
drawTurtle :: (Renderable (Path V2 n) b, TypeableFloat n) =>
Turtle n a -> QDiagram b V2 n Any
drawTurtle = runIdentity . drawTurtleT
sketchTurtleT :: (Monad m, Floating n, Ord n) => TurtleT n m a -> m (Path V2 n)
sketchTurtleT = liftM T.getTurtlePath . runTurtleT
sketchTurtle :: (Floating n, Ord n) => Turtle n a -> Path V2 n
sketchTurtle = runIdentity . sketchTurtleT
forward :: (OrderedField n, Monad m) => n -> TurtleT n m ()
forward x = ST.modify $ T.forward x
backward :: (OrderedField n, Monad m) => n -> TurtleT n m ()
backward x = ST.modify $ T.backward x
left :: (OrderedField n, Monad m) => n -> TurtleT n m ()
left d = ST.modify $ T.left d
right :: (OrderedField n, Monad m) => n -> TurtleT n m ()
right d = ST.modify $ T.right d
setHeading :: (OrderedField n, Monad m) => n -> TurtleT n m ()
setHeading d = ST.modify $ T.setHeading d
heading :: (OrderedField n, Monad m) => TurtleT n m n
heading = ST.gets (L.view deg . T.heading)
towards :: (Monad m, RealFloat n) => P2 n -> TurtleT n m ()
towards pt = ST.modify $ T.towards pt
setPos :: (OrderedField n, Monad m) => P2 n -> TurtleT n m ()
setPos p = ST.modify $ T.setPenPos p
pos :: Monad m => TurtleT n m (P2 n)
pos = ST.gets T.penPos
penUp :: (OrderedField n, Monad m) => TurtleT n m ()
penUp = ST.modify T.penUp
penDown :: (OrderedField n, Monad m) => TurtleT n m ()
penDown = ST.modify T.penDown
penHop :: (OrderedField n, Monad m) => TurtleT n m ()
penHop = ST.modify T.penHop
isDown :: Monad m => TurtleT n m Bool
isDown = ST.gets T.isPenDown
closeCurrent :: (OrderedField n, Monad m) => TurtleT n m ()
closeCurrent = ST.modify T.closeCurrent
setPenColor :: (OrderedField n, Monad m) => Colour Double -> TurtleT n m ()
setPenColor c = ST.modify $ T.setPenColor c
setPenWidth :: (OrderedField n, Monad m) => Measure n -> TurtleT n m ()
setPenWidth s = ST.modify $ T.setPenWidth s