[FF] 2008-04-23 - I was remembering having seen such a game somewhere... The purpose of this is not really the game but the challenge of implementing that functionality in Tk [Canvas]. Do you know a better way of doing it rather than such canvas [bind]s? About the game: It's about tidying up the lines so that no line crosses another line. ''You win additional 100 points if you can extend it with an algorithm that solves it, showing the progress step-by-step :-)'' [http://wiki.tcl.tk/_repo/images/FF/36859403rl0.gif] ---- canvas .c -width 480 -height 480 -background white grid .c -row 0 -column 0 -sticky news grid columnconfigure . 0 -weight 1 grid rowconfigure . 0 -weight 1 set ndots 0 set r 8 set lastx 0 set lasty 0 proc add_dot {x y} { if {$::ndots > 0} { .c create line $::lastx $::lasty $x $y -tags [list line \ [format line%02d%02d [set ::ndots] [incr ::ndots]]] } {incr ::ndots} .c create oval \ [expr $x-$::r] [expr $y-$::r] [expr $x+$::r] [expr $y+$::r] \ -fill red -tags [list dot dot$::ndots] set ::dot$::ndots 0 .c bind dot$::ndots "set ::dot$::ndots 1" .c bind dot$::ndots "set ::dot$::ndots 0" .c bind dot$::ndots " if {!\$::dot$::ndots} break set l1 [format line%02d%02d [expr $::ndots-1] $::ndots] set l2 [format line%02d%02d $::ndots [expr $::ndots+1]] set c1 \[.c coords \$l1] set c2 \[.c coords \$l2] set nc1 \[list \[lindex \$c1 0] \[lindex \$c1 1] %x %y] set nc2 \[list %x %y \[lindex \$c2 2] \[lindex \$c2 3]] .c coords \$l1 \$nc1 .c coords \$l2 \$nc2 .c coords dot$::ndots \[expr %x-$::r] \[expr %y-$::r] \[expr %x+$::r] \[expr %y+$::r] " set ::lastx $x set ::lasty $y .c lower line } for {set i 0} {$i < 30} {incr i} { add_dot [expr int(rand()*400)] [expr int(rand()*400)] } ---- [HJG] That looks like a simple version of gPlanarity, from http://web.mit.edu/xiphmont/Public/gPlanarity.html, or perhaps http://johntantalo.com/wiki/Planarity or http://www.planarity.net. See also http://www.jasondavies.com/planarity for this as a browser-game. ---- See also: [Canvas geometrical calculations] - [Polygon intersection] - [Triangle Madness] ---- !!!!!! %| [canvas] | [Category Games] | [Category GUI] |% !!!!!!