【发布时间】:2021-10-18 05:04:59
【问题描述】:
当我试图编译从互联网上获取的程序时
proc demo {} {
canvas .c -bg white
frame .f
button .f.c -text Clear -command {.c delete all}
button .f.co -text Complete -command {showComplete .c}
button .f.tr -text Triangulate -command {showTriangulate .c}
eval pack [winfo children .f] -side left
pack .c .f -fill x -expand 1
bind .c <1> {addVertex %W %x %y}
.c bind vertex <3> {%W delete current}
}
proc showComplete w {
$w delete edge
foreach edge [completeGraph [get vertex $w]] {
showEdge $w $edge
}
}
proc showEdge {w edge {fill gray}} {
regexp {(.+)/(.+),(.+)/(.+)} $edge -> x0 y0 x1 y1
set ::length($edge) [expr {hypot($x1-$x0,$y1-$y0)}]
$w create line $x0 $y0 $x1 $y1 -tags "edge $edge" -fill $fill
}
proc get {tag w} {
set res {}
foreach v [$w find withtag $tag] {
lappend res [lindex [$w gettags $v] 1]
}
set res
}
proc completeGraph vertices {
set graph {}
foreach i $vertices {
foreach j $vertices {
if {$i<$j} {lappend graph $i,$j}
}
}
set graph
}
proc showTriangulate w {
$w delete edge
showComplete $w
wm title . Wait...
set t0 [clock clicks -milliseconds]
foreach edge [triangulate [get edge $w]] {
showEdge $w $edge red
}
wm title . [expr {[clock clicks -milliseconds] - $t0}]
}
proc triangulate graph {
while 1 {
set found 0
foreach i $graph {
foreach j $graph {
if {$i!=$j && [crossing $i $j]} {
lremove graph [longer $i $j]
set found 1
break
}
}
if $found break
}
if {!$found} break
}
set graph
}
proc crossing {edge1 edge2} {
regexp {(.+)/(.+),(.+)/(.+)} $edge1 -> x0 y0 x1 y1
regexp {(.+)/(.+),(.+)/(.+)} $edge2 -> x2 y2 x3 y3
if [adjacent $x0/$y0 $x1/$y1 $x2/$y2 $x3/$y3] {return 0}
set m1 [slope $x0 $y0 $x1 $y1]
set b1 [expr {$y0-$m1*$x0}]
set m2 [slope $x2 $y2 $x3 $y3]
set b2 [expr {$y2-$m2*$x2}]
set x [slope $m2 $b1 $m1 $b2]
expr {[between $x0 $x $x1] && [between $x2 $x $x3]}
}
proc adjacent args {
expr {[llength [lsort -unique $args]]<[llength $args]}
}
proc slope {x0 y0 x1 y1} {
# slightly "bend" a vertical line, to avoid division by zero
if {$x1==$x0} {set x1 [expr {$x1+0.00000001}]}
expr {double($y1-$y0)/($x1-$x0)}
}
proc between {a b c} {
expr {$b==[lindex [lsort -real [list $a $b $c]] 1]}
}
proc longer {edge1 edge2} {
global length
expr {$length($edge1) > $length($edge2)? $edge1: $edge2}
}
proc addVertex {w x y} {
$w create rect [expr $x-2] [expr $y-2] [expr $x+2] [expr $y+2] \
-tags "vertex $x/$y" -fill blue
}
proc lremove {varName element} {
upvar 1 $varName var
set pos [lsearch $var $element]
set var [lreplace $var $pos $pos]
}
demo
bind . <Escape> {exec wish $argv0 &; exit}
bind . <F1> {console show}
无效的命令名称“画布” 在执行时 “画布 .c -bg 白色” (程序“演示”第 2 行) 从内部调用 “演示”
在此画布命令未读取。我有 nam(网络动画师),我可以编译其他程序。我想知道如何运行它。请任何人帮忙。
在 ns2 中编译时,我觉得
【问题讨论】:
-
otcl 解释器
$ ns可以运行 OTCL simulations.tcl。 -
必须在
wish或其他已加载 Tk 的 tcl 环境中运行。脚本顶部的package require Tk可能起作用,具体取决于此 ns2 的配置方式。 -
谢谢@Shawn。但是如何重新配置 ns2 以使 tk 工作
-
@KnudLarsen 谢谢先生。但是我不明白。
-
wish→ →ns-allinone-2.35/bin/wish8.5......... 使用示例:./wish8.5 canvas.tcl.......... 'ns' 是 otcl 解释器。 'ns' 并不意味着理解所有 tcl 命令。
标签: user-interface tcl ns2 nam