diff options
Diffstat (limited to 'library/demos')
-rw-r--r-- | library/demos/knightstour.tcl | 33 | ||||
-rw-r--r-- | library/demos/pendulum.tcl | 8 |
2 files changed, 28 insertions, 13 deletions
diff --git a/library/demos/knightstour.tcl b/library/demos/knightstour.tcl index 95ee6ca..89e294b 100644 --- a/library/demos/knightstour.tcl +++ b/library/demos/knightstour.tcl @@ -61,6 +61,8 @@ proc Next {square} { set minimum $count set nextSquare $testSquare } elseif {$count == $minimum} { + # to remove the enhancement to Warnsdorff's rule + # remove the next line: set nextSquare [Edgemost $nextSquare $testSquare] } } @@ -92,7 +94,7 @@ proc MovePiece {dlg last square} { $dlg.f.txt see end $dlg.f.c itemconfigure [expr {1+$last}] -state normal -outline black $dlg.f.c itemconfigure [expr {1+$square}] -state normal -outline red - $dlg.f.c coords knight [lrange [$dlg.f.c coords [expr {1+$square}]] 0 1] + $dlg.f.c moveto knight {*}[lrange [$dlg.f.c coords [expr {1+$square}]] 0 1] lappend visited $square set next [Next $square] if {$next ne -1} { @@ -125,8 +127,8 @@ proc Tour {dlg {square {}}} { $dlg.f.c itemconfigure $n -state disabled -outline black } if {$square eq {}} { - set square [expr {[$dlg.f.c find closest \ - {*}[$dlg.f.c coords knight] 0 65]-1}] + set coords [lrange [$dlg.f.c coords knight] 0 1] + set square [expr {[$dlg.f.c find closest {*}$coords 0 65]-1}] } variable initial $square after idle [list MovePiece $dlg $initial $initial] @@ -161,7 +163,7 @@ proc DragMotion {w x y} { } proc DragEnd {w x y} { set square [$w find closest $x $y 0 65] - $w coords selected [lrange [$w coords $square] 0 1] + $w moveto selected {*}[lrange [$w coords $square] 0 1] $w dtag selected variable dragging ; unset dragging } @@ -201,10 +203,21 @@ proc CreateGUI {} { -width 2 -state disabled } } - catch {eval font create KnightFont -size -24} - $c create text 0 0 -font KnightFont -text "\u265e" \ - -anchor nw -tags knight -fill black -activefill "#600000" - $c coords knight [lrange [$c coords [expr {1 + int(rand() * 64)}]] 0 1] + if {[tk windowingsystem] ne "x11"} { + catch {eval font create KnightFont -size -24} + $c create text 0 0 -font KnightFont -text "\u265e" \ + -anchor nw -tags knight -fill black -activefill "#600000" + } else { + # On X11 we cannot reliably tell if the \u265e glyph is available + # so just use a polygon + set pts { + 2 25 24 25 21 19 20 8 14 0 10 0 0 13 0 16 + 2 17 4 14 5 15 3 17 5 17 9 14 10 15 5 21 + } + $c create polygon $pts -tag knight -offset 8 \ + -fill black -activefill "#600000" + } + $c moveto knight {*}[lrange [$c coords [expr {1 + int(rand() * 64)}]] 0 1] $c bind knight <ButtonPress-1> [namespace code [list DragStart %W %x %y]] $c bind knight <Motion> [namespace code [list DragMotion %W %x %y]] $c bind knight <ButtonRelease-1> [namespace code [list DragEnd %W %x %y]] @@ -245,7 +258,9 @@ proc CreateGUI {} { tkwait window $dlg } -if {!$tcl_interactive} { +if {$tcl_interactive} { + if {[info exists widgetDemo]} { CreateGUI } +} else { if {![winfo exists .knightstour]} { if {![info exists widgetDemo]} { wm withdraw . } set r [catch [linsert $argv 0 CreateGUI] err] diff --git a/library/demos/pendulum.tcl b/library/demos/pendulum.tcl index b70cbf1..8512d24 100644 --- a/library/demos/pendulum.tcl +++ b/library/demos/pendulum.tcl @@ -3,7 +3,7 @@ # This demonstration illustrates how Tcl/Tk can be used to construct # simulations of physical systems. # -# RCS: @(#) $Id: pendulum.tcl,v 1.3 2006/10/17 05:52:40 das Exp $ +# RCS: @(#) $Id: pendulum.tcl,v 1.4 2009/04/02 08:27:51 patthoyts Exp $ if {![info exists widgetDemo]} { error "This script should be run from the \"widget\" demo." @@ -51,9 +51,9 @@ for {set i 90} {$i>=0} {incr i -10} { # Coordinates of these items don't matter; they will be set properly below $w.k create line 0 0 1 1 -smooth true -tags graph$i -fill grey$i } -# FIXME: UNICODE labels -$w.k create text 0 0 -anchor ne -text "q" -font {Symbol 8} -tags label_theta -$w.k create text 0 0 -anchor ne -text "dq" -font {Symbol 8} -tags label_dtheta + +$w.k create text 0 0 -anchor ne -text "\u03b8" -tags label_theta +$w.k create text 0 0 -anchor ne -text "\u03b4\u03b8" -tags label_dtheta pack $w.k -in $w.p.l2 -fill both -expand true # Initialize some variables |