Langton's ant: Difference between revisions

→‎{{header|Logo}}: Add implementation.
(→‎{{header|Logo}}: Add implementation.)
Line 2,848:
 
[[File:Langtons Ant Locomotive BASIC.png]]
 
=={{header|Logo}}==
<lang logo>make "size 100
make "white 1
make "black 2
make "sum sum :white :black
make "chars [. #]
make "origin quotient :size 2
make "grid mdarray (list :size :size)
make "directions [ [1 0] [0 1] [-1 0] [0 -1] ]
 
repeat size [
local "y
make "y repcount
repeat size [
mdsetitem (list repcount :y) :grid :white
]
]
make "x quotient :size 2
make "y quotient :size 2
make "direction sum 1 random count :directions
 
while [(and (:x > 0) (:x <= :size) (:y > 0) (:y <= :size))] [
local "color
make "color mditem (list :x :y) :grid
local "delta
ifelse [equal? :color :white] [
make "delta 1
] [
make "delta -1
]
make "direction sum 1 (modulo (:direction + :delta - 1) count :directions)
make "dir (item :direction :directions)
mdsetitem (list :x :y) :grid (sum :sum minus :color)
make "x sum :x first :dir
make "y sum :y last :dir
]
 
repeat size [
local "y
local "blank
make "y repcount
make "blank "true
repeat size [if ( (mditem (list repcount :y) :grid) = :black ) [make "blank "false]]
 
if [not :blank] [
repeat size [
type item (mditem (list repcount :y) :grid) :chars
]
print []
]
]
bye</logo>
 
{{Output}}
<pre>...............................................................................................##...
..............................................................................................####..
.............................................................................................#.##.#.
............................................................................................##.####.
...........................................................................................#.#.#.#.#
..........................................................................................##..#.###.
.............................##..........................................................#.#..###..#
......................##......##........................................................##..#...###.
.....................#..#..#.##.#......................................................#.#..###..#..
....................###..###.#..#.....................................................##..#...###...
....................#.####..##.#.....................................................#.#..###..#....
............................##......................................................##..#...###.....
......................##.##.##.....................................................#.#..###..#......
......................####..#.##.#................................................##..#...###.......
......................#####.##.###.##....##....##................................#.#..###..#........
.......................#..#.#.##.#..##....####..##..............................##..#...###.........
........................####.###.####....####..##.#............................#.#..###..#..........
........................###.#...#....##..##.......#...##......................##..#...###...........
.........................####.##...##..##..#......#..#..#....................#.#..###..#............
.........................#.##..#..#...##.##.......#...#..#..................##..#...###.............
.........................#.####..##.#.#.########.#....#..#.................#.#..###..#..............
.........................##..##..#..##.#.#.##.##....#.#.#.##..##..........##..#...###...............
.........................#.#..#..#..#.#....#...#.##...##..#.#####........#.#..###..#................
...........................##.####.##...#..####...#..#...##...##.#......##..#...###.................
.......................##...##########...##.#####..#.####...#....#.....#.#..###..#..................
.......................#..#..#.##..#..#...#.#..##.#####.##.#.....#....##..#...###...................
.......................#...##....#.##..#.#.....#####.#.#####.....#...#.#..###..#....................
......................#...##...###.###....#.#.##.#.##.######.#..#...##..#...###.....................
......................#.####..##.#..#...###.###.##.##...##.#..##...#.#..###..#......................
.......................##..#....##..#..#########..##..####.#......##..#...###.......................
.......................#....#....#..####..#.###########..##...#..#.#..###..#........................
......................#......#...####.####.......##...#.##..###.##..#...###.........................
......................#...#....#.#.#...##......##.#.#.###.#..#.#.#..###..#..........................
.......................#...##.####..####.#####..##..##.#.##.#.....#...###...........................
........................##..#..#.##.###......#..###.#..#....##.#..###..#............................
..........................#.....#..###.##.#..##.####.#.#..#.#...#...###.............................
.........................#...####.##..#....#..###...##.##...##..###..#..............................
.........................#.##..##.###...#.....##..#..###.##.#.#...###...............................
..........................##.....#.##.....##..#...##.##.........#..#................................
...........................##.#....####..#.#...#...###.##.#...#.#...................................
.............................##.###.#####...#.##.##.##.#.#.##.#.###.#...............................
............................#...#.###.#.######.##.##..####.#...##.###...............................
............................#.#.#.###...#..####..#.#.#####...#.....#................................
.............................###...###.....#.#.###..##.#..##.###.#..................................
..............................##..##.#..#.#...##.####.##..###..#.#..................................
..................................###..##.##.....#.....#...#..#.###.................................
..................................#.......###.........#.#.##..##....................................
....................................#....#..#.........#..#.#........................................
....................................#.##............##...###........................................
.....................................##..#..........####..#.........................................
......................................##..############..##..........................................
</pre>
 
=={{header|LOLCODE}}==
1,481

edits