Langton's ant: Difference between revisions
m
moved picolisp below PHP
m (moved picolisp below PHP) |
|||
Line 4,126:
##
</pre>
=={{header|PicoLisp}}==▼
[[File:Picolisp_ant.gif|right|thumb]]▼
This code pipes a PBM into ImageMagick's "display" to show the result:▼
<lang PicoLisp>(de ant (Width Height X Y)▼
(let (Field (make (do Height (link (need Width)))) Dir 0)▼
(until (or (le0 X) (le0 Y) (> X Width) (> Y Height))▼
(let Cell (nth Field X Y)▼
(setq Dir (% (+ (if (car Cell) 1 3) Dir) 4))▼
(set Cell (not (car Cell))) ▼
(case Dir▼
(0 (inc 'X))▼
(1 (inc 'Y))▼
(2 (dec 'X))▼
(3 (dec 'Y)) ) ) )▼
(prinl "P1")▼
(prinl Width " " Height)▼
(for Row Field▼
(prinl (mapcar '[(X) (if X 1 0)] Row)) ) ) )▼
(out '(display -) (ant 100 100 50 50))▼
(bye)▼
</lang>▼
=={{header|PHP}}==
Line 4,209 ⟶ 4,187:
// SAVE IMAGE
imagepng($img, dest_name);
▲</lang>
▲=={{header|PicoLisp}}==
▲[[File:Picolisp_ant.gif|right|thumb]]
▲This code pipes a PBM into ImageMagick's "display" to show the result:
▲<lang PicoLisp>(de ant (Width Height X Y)
▲ (let (Field (make (do Height (link (need Width)))) Dir 0)
▲ (until (or (le0 X) (le0 Y) (> X Width) (> Y Height))
▲ (let Cell (nth Field X Y)
▲ (setq Dir (% (+ (if (car Cell) 1 3) Dir) 4))
▲ (set Cell (not (car Cell)))
▲ (case Dir
▲ (0 (inc 'X))
▲ (1 (inc 'Y))
▲ (2 (dec 'X))
▲ (3 (dec 'Y)) ) ) )
▲ (prinl "P1")
▲ (prinl Width " " Height)
▲ (for Row Field
▲ (prinl (mapcar '[(X) (if X 1 0)] Row)) ) ) )
▲(out '(display -) (ant 100 100 50 50))
▲(bye)
</lang>
|