if 0 {[Richard Suchenwirth] 2005-06-03 - Here's a tiny toy to simulate the game of Lotto, where six or seven numbers out of 1..49 are drawn. [http://mini.net/files/lotto.jpg] Click on the canvas to start a drawing. Six numbers are randomly selected and marked with a red circle, a seventh one ("extra number") is marked in yellow.} proc main {} { set dx 15 set dy 15 pack [canvas .c -width [expr {$dx*8}] -height [expr {$dy*9}]] set x $dx; set y $dy foreach i [iota1 49] { .c create text $x $y -text $i if {$i%7} { incr x $dx } else {set x $dx; incr y $dy} } .c create text [expr {4.5*$dx}] $y -text "Click to draw" bind .c <1> {draw .c} } proc draw w { $w delete marked set numbers [iota1 49] foreach i {1 2 3 4 5 6} { set number [ldraw numbers] $w create oval [$w bbox $number] -fill {} -outline red \ -width 2 -tag marked update idletasks after 500 } set extra [ldraw numbers] $w create oval [$w bbox $extra] -fill {} -outline yellow \ -width 2 -tag marked $w lower marked } #------------------ Generally useful functions: proc iota1 n { set res {} for {set i 1} {$i<=$n} {incr i} {lappend res $i} set res } proc ldraw _list { upvar 1 $_list list set pos [expr {int(rand()*[llength $list])}] K [lindex $list $pos] [set list [lreplace $list $pos $pos]] } proc K {a b} {set a} #---------------------------------------------------- main if 0 { ---- [Category Toy] - [Arts and crafts of Tcl-Tk programming] }