no display name and no $DISPLAY environment variable
    while executing
"load /enadisk/commun/linux/local/ActiveTcl-8.6.11/lib/libtk8.6.so Tk"
    ("package ifneeded Tk 8.6.11" script)
    invoked from within
"package require Tk"
    (in namespace eval "::request" script line 6)
    invoked from within
"namespace eval ::request $script"
    ("::try" body line 12)

OUTPUT BUFFER:

#!/bin/sh #\ exec wish "$0" ${1+"$@"} # Simple simulation of Braitenburg vehicles. # Car drawing code stolen from "Car Racing in Tcl" - http://wiki.tcl.tk/4364 package require Tk set tcl_precision 17 namespace eval car { variable cars [list] } # Create a new car: # params: # name - a name for the car # c - the canvas to draw on # color - colo(u)r of this car # angle - initial direction of motion # inputs - list of inputs in form (e.g.): # left input light + -> left wheel proc car::new {name c x y color angle inputs} { variable cars lappend cars $name interp alias {} $name {} car::dispatch $name namespace eval $name { variable lspeed 10 rspeed 10 variable ldiff 0 rdiff 0 variable inputs [list] } namespace eval $name [list variable canvas $c angle $angle] interp alias {} $name: {} namespace eval ::car::$name $c create line $x [expr {$y + 5}] [expr {$x + 20}] [expr {$y + 5}] \ -tag [list $name object] -width 3 $c create line [expr {$x - 2}] [expr {$y + 40}] [expr {$x + 22}] \ [expr {$y + 40}] -tag [list $name object] -width 3 $c create poly [expr {$x + 2}] $y [expr {$x + 18}] $y \ [expr {$x + 20}] [expr {$y + 50}] $x [expr {$y + 50}]\ -fill $color -tags [list $name object] # Create the wheels wheel $name $c [expr {$x - 3}] [expr {$y + 5}] wheel $name $c [expr {$x + 23}] [expr {$y + 5}] wheel $name $c [expr {$x - 5}] [expr {$y + 40}] wheel $name $c [expr {$x + 25}] [expr {$y + 40}] canvas'rotate $c $name $angle # Run through the inputs sections adding the inputs set RE \ {(left|right|center)\s+input\s+(.+)\s+(\+|-)\s+->\s+(left|right)\s+wheel} foreach line [split $inputs \n] { if {[regexp $RE $line -> iside type posneg wside]} { # Create the input lappend ${name}::inputs [list $iside $type $posneg $wside] } } } proc car::wheel {name c x y {dx 3} {dy 6}} { set x0 [expr {$x - $dx}] set y0 [expr {$y - $dy}] set x1 [expr {$x + $dx}] set y1 [expr {$y + $dy}] $c create poly $x0 $y0 $x0 $y1 $x1 $y1 $x1 $y0 -fill black \ -tag [list $name object] } proc car::dispatch {name cmd args} {eval ::car::$cmd $name $args} proc car::move {} { variable cars global hits foreach name $cars { set c [$name: set canvas] # Work out the change in angle, by comparing the left and right wheel # speeds. set angle [$name: set angle] set rspeed [expr {[$name: set rspeed] + [$name: set rdiff]}] set lspeed [expr {[$name: set lspeed] + [$name: set ldiff]}] set nangle [expr {($rspeed - $lspeed)/5.}] # Mean speed set speed [expr {($rspeed + $lspeed)/2.}] canvas'rotate $c $name $nangle $name: set angle [expr {$angle + $nangle}] set dx [expr {-$speed * sin([$name: set angle])}] set dy [expr {-$speed * cos([$name: set angle])}] $c move $name $dx $dy # Turn back from walls foreach {x0 y0 x1 y1} [$c bbox $name] { break } if {$x1 < 0} { $c move $name [winfo width $c] 0 } if {$x0 > [winfo width $c]} { $c move $name -[winfo width $c] 0 } if {$y1 < 0} { $c move $name 0 [winfo height $c] } if {$y0 > [winfo height $c]} { $c move $name 0 -[winfo height $c] } # See if we have collided with any objects foreach {x y} [canvas'center $c $name] { break } set start {} set closest [$c find closest $x $y 30] while {$closest != $start} { if {[info exists hits($closest)]} { if {[incr hits($closest) -1] <= 0} { # Item is now "dead" set next [$c find closest $x $y 30 $closest] $c delete $closest set closest $next continue } # Flash the item to indicate it is hit set color [$c itemcget $closest -fill] $c itemconfigure $closest -fill white after 20 [list $c itemconfigure $closest -fill $color] } if {![string length $start]} {set start $closest } set closest [$c find closest $x $y 30 $closest] } # Find nearby objects and adjust speeds appropriately # Work out position of left and right inputs # Precomputed hypot and angle to corners set hypot 25.0 set phi 0.411516846067 set rx [expr {$x + $hypot * sin([$name: set angle] + $phi)}] set ry [expr {$y + $hypot * cos([$name: set angle] + $phi)}] set lx [expr {$x + $hypot * sin([$name: set angle] - $phi)}] set ly [expr {$y + $hypot * cos([$name: set angle] - $phi)}] set cx [expr {$x + $hypot * sin([$name: set angle])}] set cy [expr {$y + $hypot * cos([$name: set angle])}] array set totals { right,inputs 0 left,inputs 0 right,total 0 left,total 0 } foreach item [$name: set inputs] { foreach {iside type posneg wside} $item { break } # Find all overlapping items of the right type in a certain radius # (50 pixels) set start {} if {"$iside" == "left"} { set sx $lx set sy $ly } elseif {"$iside" == "right"} { set sx $rx set sy $ry } else { # Center set sx $cx set sy $cy } set closest [$c find closest $sx $sy 100] while {$closest != $start} { # Check the tag if {[lsearch [$c gettags $closest] $name] == -1} { if {[lsearch [$c gettags $closest] $type] > -1} { # Find distance from sensor foreach {ox oy} [canvas'center $c $closest] { break } set distance \ [expr {150-hypot(abs($ox-$sx),abs($oy-$sy))}] # Add to total set totals($wside,total) [expr $totals($wside,total) \ $posneg $distance] incr totals($wside,inputs) } } if {![string length $start]} { set start $closest } set closest [$c find closest $sx $sy 100 $closest] } } if {$totals(right,inputs) > 0} { set dr [expr {$totals(right,total) / $totals(right,inputs)}] if {$dr < -100} { set dr -100 } $name: set rdiff [expr {$dr / 10.0}] } else { $name: set rdiff 0 } if {$totals(left,inputs) > 0} { set dl [expr {$totals(left,total) / $totals(left,inputs)}] if {$dl < -100} { set dl -100 } $name: set ldiff [expr {$dl / 10.0}] } else { $name: set ldiff 0 } } } proc object {c x y} { global source hits switch $source { object { set color blue } light { set color yellow } temp { set color red } oxygen { set color cyan } organic { set color green } } set id [$c create oval $x $y [expr {$x + 20}] [expr {$y + 20}] \ -fill $color -tags $source] set hits($id) 15 $c bind $id [list $c delete $id] } proc canvas'center {w tag} { foreach {x0 y0 x1 y1} [$w bbox $tag] { break } list [expr {($x0 + $x1) / 2.}] [expr {($y0 + $y1) / 2.}] } proc canvas'rotate {w tag angle} { foreach {xm ym} [canvas'center $w $tag] { break } foreach item [$w find withtag $tag] { set coords {} foreach {x y} [$w coords $item] { set rad [expr {hypot($x-$xm, $y-$ym)}] set th [expr {atan2($y-$ym, $x-$xm)}] lappend coords [expr {$xm + $rad * cos($th - $angle)}] lappend coords [expr {$ym + $rad * sin($th - $angle)}] } $w coords $item $coords } } proc every {ms body} {eval $body; after $ms [info level 0]} # Create a means to add new sources to the landscape set source "light" frame .s label .s.source -text "Source:" radiobutton .s.light -text "Light" -variable ::source -value "light" radiobutton .s.obstacle -text "Object" -variable ::source -value "object" radiobutton .s.temp -text "Temp." -variable ::source -value "temp" radiobutton .s.oxygen -text "Oxygen" -variable ::source -value "oxygen" radiobutton .s.organic -text "Organic Matter" -variable ::source \ -value "organic" eval [list pack] [winfo children .s] [list -side left] pack .s -side top # Create the landscape pack [canvas .c -width 600 -height 400 -bg white] -fill both -expand 1 car::new foo .c 200 200 red 0.2 { left input light + -> right wheel right input light + -> left wheel left input temp + -> left wheel right input temp + -> right wheel left input oxygen - -> right wheel right input oxygen - -> left wheel left input organic - -> left wheel right input organic - -> right wheel } bind .c { object .c %x %y } bind .c { break } every 50 {car::move}