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.Identity (Identity (..))
import qualified Control.Monad.State as ST
import Diagrams.Prelude
import qualified Diagrams.TwoD.Path.Turtle.Internal as T
type TurtleT = ST.StateT T.TurtleState
type Turtle = TurtleT Identity
runTurtleT :: Monad m => TurtleT m a -> m T.TurtleState
runTurtleT t = ST.execStateT t T.startTurtle
runTurtle :: Turtle a -> T.TurtleState
runTurtle = runIdentity . runTurtleT
drawTurtleT :: (Monad m, Functor m, Renderable (Path R2) b)
=> TurtleT m a -> m (Diagram b R2)
drawTurtleT = fmap T.getTurtleDiagram . runTurtleT
drawTurtle :: (Renderable (Path R2) b) => Turtle a -> Diagram b R2
drawTurtle = runIdentity . drawTurtleT
sketchTurtleT :: (Functor m, Monad m) => TurtleT m a -> m (Path R2)
sketchTurtleT = fmap T.getTurtlePath . runTurtleT
sketchTurtle :: Turtle a -> Path R2
sketchTurtle = runIdentity . sketchTurtleT
forward :: Monad m => Double -> TurtleT m ()
forward x = ST.modify $ T.forward x
backward :: Monad m => Double -> TurtleT m ()
backward x = ST.modify $ T.backward x
left :: Monad m => Double -> TurtleT m ()
left d = ST.modify $ T.left d
right :: Monad m => Double -> TurtleT m ()
right d = ST.modify $ T.right d
setHeading :: Monad m => Double -> TurtleT m ()
setHeading d = ST.modify $ T.setHeading d
heading :: Monad m => TurtleT m Double
heading = ST.gets (L.view deg . T.heading)
towards :: Monad m => P2 -> TurtleT m ()
towards pt = ST.modify $ T.towards pt
setPos :: Monad m => P2 -> TurtleT m ()
setPos p = ST.modify $ T.setPenPos p
pos :: Monad m => TurtleT m P2
pos = ST.gets T.penPos
penUp :: Monad m => TurtleT m ()
penUp = ST.modify T.penUp
penDown :: Monad m => TurtleT m ()
penDown = ST.modify T.penDown
penHop :: Monad m => TurtleT m ()
penHop = ST.modify T.penHop
isDown :: Monad m => TurtleT m Bool
isDown = ST.gets T.isPenDown
closeCurrent :: Monad m => TurtleT m ()
closeCurrent = ST.modify T.closeCurrent
setPenColor :: Monad m => Colour Double -> TurtleT m ()
setPenColor c = ST.modify $ T.setPenColor c
setPenWidth :: Monad m => Double -> TurtleT m ()
setPenWidth s = ST.modify $ T.setPenWidth s