-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Turtle graphics. -- -- Have you ever heard of Turtle Graphics? -- -- No? Think of a turtle as a cursor you can program to draw -- graphics! -- -- Turtle graphics are a fantastic introduction to the world of -- programming and to the syntax of a new programming language. -- -- -- This module is a framework built on top of Graphics.Gloss to -- render turtles programmed in Haskell as animations. This is primarily -- aimed as a teaching tool to beginners - but also, it's cool to draw -- things! -- -- See The API ref, Graphics.WorldTurtle, for features! @package worldturtle @version 0.1.0.0 -- | This module exposes shapes not found in gloss but may be found to be -- worthwhile. module Graphics.WorldTurtle.Shapes -- | Creates the default turtle polygon arrow with a given outline color -- and fill color. turtleArrow :: Color -> Color -> Picture -- | Draws a line from a start-point to an end-point with a given -- thickness. thickLine :: Point -> Point -> Float -> Picture -- | This module is a collection of all the commands used to manipulate a -- turtle! module Graphics.WorldTurtle.Commands -- | The Turtle that is drawn on the canvas! Create a new turtle using -- makeTurtle. data Turtle -- | Creates a new Turtle and displays it on the canvas. This turtle -- can then be manipulated! For example, to create a turtle and then move -- the turtle forward: -- --
--   main:: IO ()
--   main = runTurtle $ do
--     t <- makeTurtle
--     forward 90 t
--   
--   
-- -- The default turtle starts at position (0, 0) and is orientated -- North. makeTurtle :: TurtleCommand Turtle -- | This variant of makeTurtle takes a starting position, a -- starting orientation, and a color to apply to the turtle and the -- turtle's pen. -- --
--   myCommand :: TurtleCommand ()
--   myCommand = do
--     t1 <- makeTurtle' (0, 0)  0 green
--     t2 <- makeTurtle' (0, 0) 90 red
--     forward 90 t1 <|> forward 90 t2
--   
--   
-- -- See makeTurtle. makeTurtle' :: Point -> Float -> Color -> TurtleCommand Turtle -- | A point on the x-y plane. type Point = (Float, Float) -- | Move the turtle forward by the specified distance, in the -- direction the turtle is headed. forward :: Float -> Turtle -> TurtleCommand () -- | Shorthand for forward. fd :: Float -> Turtle -> TurtleCommand () -- | Move the turtle backward by the specified distance, in the -- direction the turtle is headed. backward :: Float -> Turtle -> TurtleCommand () -- | Shorthand for backward. bk :: Float -> Turtle -> TurtleCommand () -- | Turn a turtle left by the given degrees amount. left :: Float -> Turtle -> TurtleCommand () -- | Shorthand for left. lt :: Float -> Turtle -> TurtleCommand () -- | Turn a turtle right by the given degrees amount. right :: Float -> Turtle -> TurtleCommand () -- | Shorthand for right. rt :: Float -> Turtle -> TurtleCommand () -- | Draw an arc with a given radius. The center is -- radius units left of the turtle if positive. -- Otherwise radius units right of the turtle if -- negative. -- -- The arc is drawn in an anticlockwise direction if the radius is -- positive, otherwise, it is drawn in a clockwise direction. circle :: Float -> Float -> Turtle -> TurtleCommand () -- | Warps the turtle to a new position. The turtle jumps to this new -- position with no animation. If the pen is down then a line is drawn. goto :: Point -> Turtle -> TurtleCommand () -- | Alias of goto. setPosition :: Point -> Turtle -> TurtleCommand () -- | Warps the turtle to its starting position (0, 0) and resets -- the orientation to North (90 degrees). No line is drawn -- moving the turtle. home :: Turtle -> TurtleCommand () -- | Sets the turtle's heading. See heading. setHeading :: Float -> Turtle -> TurtleCommand () -- | Sets the turtle's speed. See speed. setSpeed :: Float -> Turtle -> TurtleCommand () -- | Stamp a copy of the turtle shape onto the canvas at the current turtle -- position. stamp :: Turtle -> TurtleCommand () -- | Gets the turtle's representation as a Gloss Picture. representation :: Turtle -> TurtleCommand Picture -- | Returns the turtle's current position. Default (starting) position is -- (0, 0). position :: Turtle -> TurtleCommand Point -- | Returns the turtle's heading. -- -- 0 is along the positive x-axis, going anticlockwise. So: -- -- -- -- The default heading is North (90 degrees). heading :: Turtle -> TurtleCommand Float -- | Returns whether the turtle's current speed. Speed is is -- distance per second. A speed of 0 is equivalent to no -- animation being performed and instant drawing. The default value is -- 200. speed :: Turtle -> TurtleCommand Float -- | Returns the turtle's pen color. The color of the turtle's pen.The -- default color is black. penColor :: Turtle -> TurtleCommand Color -- | Returns whether the turtle's pen is down. When the turtle's pen is -- down it will draw a line when it moves. The default value is -- true. penDown :: Turtle -> TurtleCommand Bool -- | Returns the turtle's pen size. Defaults to 2. penSize :: Turtle -> TurtleCommand Float -- | Returns whether the turtle is visible. The default value is -- true. visible :: Turtle -> TurtleCommand Bool -- | Set the turtle's pen color. See penColor. setPenColor :: Color -> Turtle -> TurtleCommand () -- | Sets the turtle's pen to down or up. See penDown. setPenDown :: Bool -> Turtle -> TurtleCommand () -- | Sets the turtle's pen size. See penSize. setPenSize :: Float -> Turtle -> TurtleCommand () -- | Sets the turtle's representation to a Gloss Picture. See -- representation. For example, to set the turtle as a red circle: -- --
--   import Graphics.WorldTurtle
--   import qualified Graphics.Gloss.Data.Picture as G
--   
--   myCommand :: TurtleCommand ()
--   myCommand = do
--     t <- makeTurtle
--     setPenColor red t
--     setRepresentation (G.color red $ G.circleSolid 10) t
--     forward 90 t
--   
--   
setRepresentation :: Picture -> Turtle -> TurtleCommand () -- | Sets the turtle's visibility. See visible. setVisible :: Bool -> Turtle -> TurtleCommand () -- | Clears all drawings form the canvas. Does not alter any turtle's -- state. clear :: TurtleCommand () -- | 0 degrees. east :: Float -- | 90 degrees. north :: Float -- | 180 degrees. west :: Float -- | 270 degrees. south :: Float -- | Graphics.WorldTurtle is a module for writing and rendering -- turtle graphics in Haskell. module Graphics.WorldTurtle -- | A TurtleCommand represents an instruction to execute. It could -- be as simple as "draw a line" or more complicated like "draw 300 -- circles." -- -- TurtleCommands can be executed in order by combining them using -- the monadic operator (>>). -- -- Here is an example of how to write a function that when given a -- size and a turtle, will return a new -- TurtleCommand which will draw a square with a length and -- breadth of size using turtle. -- --
--   drawSquare :: Float -> Turtle -> TurtleCommand ()
--   drawSquare size t = replicateM_ 4 $ forward size t >> right 90 t
--   
--   
-- -- This draws a square by doing the following in order: -- -- data TurtleCommand a -- | runTurtle takes a TurtleCommand and produces the -- animation in a new window! -- -- The simplest way to run runTurtle is to execute it directly -- from your main function like so: -- --
--   main :: IO ()
--   main = runTurtle yourOwnCoolCommand
--   
--   
-- -- While running, you can interact with the window in the following way: -- -- TODO: table runTurtle :: TurtleCommand () -> IO () -- | An associative binary operation (<|>) :: Alternative f => f a -> f a -> f a infixl 3 <|>