Anonymous user
Langton's ant: Difference between revisions
m
→{{header|Haskell}}: some typos
(→{{header|Haskell}}: Replaced by more transparent and idiomatic solution) |
m (→{{header|Haskell}}: some typos) |
||
Line 2,929:
<lang Haskell>data State = State { antPosition :: Point
, antDirection :: Point
,
Now we are ready to express the main part of the algorithm
Line 2,949:
task = iterate step
>>> dropWhile ((< 50) . distance . antPosition)
>>> head >>>
where distance (x,y) = max (abs x) (abs y)</lang>
Line 2,959:
main = display w white (draw (task initial))
where
w = InWindow "Langton's Ant" (400,400) (0,0)
initial = State (0,0) (1,0) mempty
draw = foldMap drawCell
Line 2,967:
<lang haskell>main = simulate w white 500 initial draw (\_ _ -> step)
where
w = InWindow "Langton's Ant" (400,400) (0,0)
initial = State (0,0) (1,0) mempty
draw (State p _ s) = pictures [foldMap drawCell s, color red $ drawCell p]
|