Posted to tcl by emiliano at Tue Nov 04 14:16:09 GMT 2008view pretty
package require Tk 8.5 namespace path tcl::mathop pack [canvas .c -bg white] .c create line { 0 0 10 1 20 4 30 9 40 16 50 25 60 36 70 49 80 64 90 81 100 100 110 121 120 144 130 169 140 196 } -tags line .c create oval {0 0 5 5} -fill red -tags circle .c create text 150 10 -text "Mouse: " -tags MC -anchor w .c create text 150 25 -text "Point: " -tags PC -anchor w proc CenterCircle {x y} { .c coords circle [- $x 2.5] [- $y 2.5] [+ $x 2.5] [+ $y 2.5] } proc FollowMouse {x y} { set idx [.c index line @$x,$y] set clist [.c coords line] lassign [lrange $clist $idx ${idx}+1] X Y if {$X eq ""} return CenterCircle $X $Y .c itemconfigure MC -text [format "Mouse: %.1f,%.1f" $x $y] .c itemconfigure PC -text [format "Point: %.1f,%.1f" $X $Y] } bind .c <Motion> {FollowMouse %x %y} # move the mouse cursor along the curve down and up again. # some horizontal ticks will appear. # for an example see http://img145.imageshack.us/my.php?image=outputuw1.png