@@ -45,6 +45,7 @@ module Graphics.WorldTurtle.Commands
45
45
, setRotationSpeed
46
46
-- * Styling commands.
47
47
, stamp
48
+ , representation
48
49
-- ** Query turtle's state.
49
50
, position
50
51
, heading
@@ -53,7 +54,6 @@ module Graphics.WorldTurtle.Commands
53
54
, penColor
54
55
, penDown
55
56
, penSize
56
- , representation
57
57
, visible
58
58
-- ** Mutate turtle's state.
59
59
, branch
@@ -90,24 +90,29 @@ import Graphics.Gloss.Data.Picture
90
90
Creates a new `Turtle` and displays it on the canvas. This turtle can then be
91
91
manipulated! For example, to create a turtle and then move the turtle forward:
92
92
93
- > main:: IO ()
94
- > main = runWorld $ do
95
- > t <- makeTurtle
96
- > t >/> forward 90
93
+ @
94
+ main:: IO ()
95
+ main = runWorld $ do
96
+ t <- makeTurtle
97
+ t >/> forward 90
98
+ @
99
+
100
+ The default turtle starts at position (0, 0) and is orientated `north`.
97
101
98
- The default turtle starts at position @(0, 0)@ and is orientated `north`.
99
102
-}
100
103
makeTurtle :: WorldCommand Turtle
101
104
makeTurtle = WorldCommand generateTurtle
102
105
103
106
{-| This variant of `makeTurtle` takes a starting position, a starting
104
107
orientation, and a color to apply to the turtle and the turtle's pen.
105
108
106
- > myCommand :: WorldCommand ()
107
- > myCommand = do
108
- > t1 <- makeTurtle' (0, 0) 0 green
109
- > t2 <- makeTurtle' (0, 0) 90 red
110
- > t1 >/> forward 90 <|> t2 >/> forward 90
109
+ @
110
+ myCommand :: WorldCommand ()
111
+ myCommand = do
112
+ t1 <- makeTurtle' (0, 0) 0 green
113
+ t2 <- makeTurtle' (0, 0) 90 red
114
+ (t1 >/> forward 90) \<|\> (t2 >/> forward 90)
115
+ @
111
116
112
117
See `makeTurtle`.
113
118
-}
@@ -203,7 +208,7 @@ rotateTo_ rightBias !r = TurtleCommand $ \ turtle -> do
203
208
turtLens_ turtle . T. heading .= newHeading
204
209
205
210
-- | Draw a circle with a given @radius@. The center is @radius@ units left of
206
- -- the turtle if positive. Otherwise @radius@ units right of the turtle
211
+ -- the @ turtle@ if positive. Otherwise @radius@ units right of the @ turtle@
207
212
-- if negative.
208
213
--
209
214
-- The circle is drawn in an anticlockwise direction if the radius is
@@ -244,7 +249,7 @@ calculateNewPointC_ !p !radius !startAngle !angle = (px, py)
244
249
else startAngle - angle
245
250
246
251
-- | Draw an arc with a given @radius@. The center is @radius@ units left of the
247
- -- turtle if positive. Otherwise @radius@ units right of the turtle if
252
+ -- @ turtle@ if positive. Otherwise @radius@ units right of the @ turtle@ if
248
253
-- negative.
249
254
--
250
255
-- The arc is drawn in an anticlockwise direction if the radius is positive,
@@ -282,7 +287,7 @@ position :: TurtleCommand P.Point -- ^ Returned current point.
282
287
position = getter_ (0 , 0 ) T. position
283
288
284
289
-- | Warps the turtle to its starting position @(0, 0)@ and resets the
285
- -- orientation to `north` (@90@ degrees). No line is drawn moving the turtle.
290
+ -- orientation to @North@ (90 degrees). No line is drawn moving the turtle.
286
291
home :: TurtleCommand ()
287
292
home = TurtleCommand $ \ turtle -> do
288
293
let ts = turtLens_ turtle
@@ -373,7 +378,7 @@ setVisible = setter_ T.visible
373
378
374
379
-- | Returns the turtle's current speed.
375
380
-- Speed is is @distance@ per second.
376
- -- A speed of @0@ is equivalent to no animation being performed and instant
381
+ -- A speed of @0 is equivalent to no animation being performed and instant
377
382
-- movement.
378
383
-- The default value is @200@.
379
384
speed :: TurtleCommand Float -- ^ Speed of turtle.
@@ -407,14 +412,16 @@ representation = getter_ blank T.representation
407
412
See `representation`.
408
413
For example, to set the turtle as a red circle:
409
414
410
- > import Graphics.WorldTurtle
411
- > import qualified Graphics.Gloss.Data.Picture as G
412
- >
413
- > myCommand :: TurtleCommand ()
414
- > myCommand = do
415
- > setPenColor red
416
- > setRepresentation (G.color red $ G.circleSolid 10)
417
- > forward 90
415
+ @
416
+ import Graphics.WorldTurtle
417
+ import qualified Graphics.Gloss.Data.Picture as G
418
+
419
+ myCommand :: TurtleCommand ()
420
+ myCommand = do
421
+ setPenColor red
422
+ setRepresentation (G.color red $ G.circleSolid 10)
423
+ forward 90
424
+ @
418
425
-}
419
426
setRepresentation :: Picture -- ^ Picture to apply.
420
427
-> TurtleCommand ()
@@ -427,7 +434,7 @@ clear = WorldCommand $ pics .= []
427
434
-- | Sleep for a given amount of time in seconds. When sleeping no animation
428
435
-- runs. A negative value will be clamped to @0@.
429
436
sleep :: Float -> WorldCommand ()
430
- sleep = WorldCommand . decrementSimTime . max 0
437
+ sleep = WorldCommand . ( \ t -> decrementSimTime t () ) . max 0
431
438
432
439
-- | Given a command, runs the command, then resets the turtle's state back to
433
440
-- what the state was before the command was run.
@@ -463,8 +470,8 @@ south = 270
463
470
turtLens_ :: Applicative f
464
471
=> Turtle
465
472
-> (T. TurtleData -> f T. TurtleData )
466
- -> TSC b
467
- -> f ( TSC b )
473
+ -> TSC
474
+ -> f TSC
468
475
turtLens_ t = turtles . ix t
469
476
{-# INLINE turtLens_ #-}
470
477
0 commit comments