Langton's ant: Difference between revisions

(→‎{{header|Haskell}}: simplify let's in nextState)
Line 1,951:
....................................................................................................</pre>
 
=={{header|TclRunbasic}}==
<lang Runbasic>
{{libheader|Tk}}
'move up=1 right=2 down=3 left=4
[[File:LangtonAnt_Tcl.gif|thumb|Output of Tcl solution of Langton's ant task]]
' ---------------------------------
<lang tcl>package require Tk
dim plane(100,100)
x = 50: y = 50
mx = 100
 
while (x>0) and (x<100) and (y>0) and (y<100)
proc step {workarea} {
if plane(x,y) then
global x y dir
nxt = nxt - 1
if {[lindex [$workarea get $x $y] 0]} {
if nxt < 1 then nxt = 4
$workarea put black -to $x $y
else
if {[incr dir] > 3} {set dir 0}
nxt }= elsenxt {+ 1
if nxt > 4 then nxt = 1
$workarea put white -to $x $y
end if
if {[incr dir -1] < 0} {set dir 3}
}
switch $dir {
0 {incr x}
1 {incr y}
2 {incr x -1}
3 {incr y -1}
}
expr {$x < 0 || $x >= [image width $workarea] || $y < 0 || $y >= [image height $workarea]}
}
 
x = x + (nxt = 2) - (nxt = 4)
image create photo antgrid -width 100 -height 100
y = y + (nxt = 3) - (nxt = 1)
pack [label .l -image antgrid]
plane(x,y) =(plane(x,y) <> 1)
antgrid put white -to 0 0 99 99
mx = min(x,mx)
set x [set y 50]
wend
set dir 0
 
for x = mx to 100
while 1 {
for y update= 1 to 100
print chr$((plane(x,y)*3) + 32);
if {[step antgrid]} break
next y
}
print x
 
next x
# Produce output in file
</lang>
antgrid write ant.gif -format gif</lang>
 
=={{header|TI-83 BASIC}}==
23

edits