Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Langtons-ant/OCaml/langtons-ant.ocaml
Normal file
32
Task/Langtons-ant/OCaml/langtons-ant.ocaml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
open Graphics
|
||||
|
||||
type dir = North | East | South | West
|
||||
|
||||
let turn_left = function
|
||||
| North -> West
|
||||
| East -> North
|
||||
| South -> East
|
||||
| West -> South
|
||||
|
||||
let turn_right = function
|
||||
| North -> East
|
||||
| East -> South
|
||||
| South -> West
|
||||
| West -> North
|
||||
|
||||
let move (x, y) = function
|
||||
| North -> x, y + 1
|
||||
| East -> x + 1, y
|
||||
| South -> x, y - 1
|
||||
| West -> x - 1, y
|
||||
|
||||
let () =
|
||||
open_graph "";
|
||||
let rec loop (x, y as pos) dir =
|
||||
let color = point_color x y in
|
||||
set_color (if color = white then black else white);
|
||||
plot x y;
|
||||
let dir = (if color = white then turn_right else turn_left) dir in
|
||||
if not(key_pressed()) then loop (move pos dir) dir
|
||||
in
|
||||
loop (size_x()/2, size_y()/2) North
|
||||
Loading…
Add table
Add a link
Reference in a new issue