Jump to content

Langton's ant: Difference between revisions

→‎Tcl: Added implementation (output to come…)
m (→‎{{header|C sharp|C#}}: corrected lang declaration)
(→‎Tcl: Added implementation (output to come…))
Line 1,253:
....................................................................................................
....................................................................................................</pre>
 
=={{header|Tcl}}==
{{libheader|Tk}}
<lang tcl>package require Tk
 
proc step {workarea} {
global x y dir
if {[lindex [$workarea get $x $y] 0]} {
$workarea put black -to $x $y
if {[incr dir] > 3} {set dir 0}
} else {
$workarea put white -to $x $y
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]}
}
 
image create photo antgrid -width 100 -height 100
pack [label .l -image antgrid]
antgrid put white -to 0 0 99 99
set x [set y 50]
set dir 0
 
while 1 {
update
if {[step]} break
}
 
# Produce output in file
antgrid write ant.gif -format gif</lang>
 
=={{header|TI-83 BASIC}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.