aUCBLogo Demos and Tests / ant
be ant
norefresh
ht
cs
t=timefine
start=100
finish=200
for [i start finish]
[ for [j start finish]
[ make (word "field :i :j) 0
]
]
n=20000
antx=(start+finish)/2
anty=(start+finish)/2
jump=3
stepcount=0
framedelay=20
append=false
for [a 1 n]
[ ifelse (or antx<start anty<start antx>finish anty>finish)
[ print [error: ant went to far]
(pr timefine-t "sec)
stop
]
[move]
if (mod a 20)==0
[ updateGraph
]
]
(pr timefine-t "sec)
refresh
be move
ifelse (thing (word "field :antx :anty)) ==0
[ squareblack :jump rt 90 fd :jump
make (word "field :antx :anty) 1
][ squarewhite :jump lt 90 fd :jump
make (word "field :antx :anty) 0
]
ifelse or (heading==90) (heading==270)
[ ifelse (heading==90)
[ antx=antx+1
][ antx=antx-1
]
][ ifelse (heading==0)
[ anty=anty+1
][ anty=anty-1
]
]
end
be squareblack :size
setpc 0
pd
fd (:size-1)/2
rt 90
repeat :size-1
[ fd (:size-1)/2
bk :size-1
fd (:size-1)/2
rt 90 fd 1 lt 90
]
fd (:size-1)/2 bk :size-1 fd (:size-1)/2
lt 90 fd (:size-1)/2
penup
stepcount=stepcount+1
; if :stepcount == :framedelay
; [ (gifsave "ant.gif 0 :append 0)
; stepcount=0
; append=true
; ]
end
be squarewhite :size
setpc 7
pd
fd (:size-1)/2
rt 90
repeat :size-1
[ fd (:size-1)/2
bk :size-1
fd (:size-1)/2
rt 90 fd 1 lt 90
]
fd (:size-1)/2 bk :size-1 fd (:size-1)/2
lt 90 fd (:size-1)/2
penup
stepcount=stepcount+1
; if :stepcount == :framedelay
; [ (gifsave "ant.gif 0 :append 0)
; stepcount=0
; append=true
; ]
end
end