RosettaCodeData/Task/Langtons-ant/Logo/langtons-ant.logo
2015-02-20 00:35:01 -05:00

51 lines
1.1 KiB
Text

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