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}]] pack [canvas .c -width [expr {$dx*8}] -height [expr {$dy*8}] -bg gray88] 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*$dx}] $y -text "Click to draw" button .b -text "Draw" -command {draw .c} pack .b #bind .c <1> {draw .c} bind .c <1> {click .c} } proc click w { puts "Click: [winfo pointerx $w] [winfo pointery $w]" # Todo: Build list of own tip } proc draw w { global DrawNr incr DrawNr $w delete marked set numbers [iota1 49] foreach i [iota1 6] { #circle $w [$w bbox [ldraw numbers]] red set n [ldraw numbers] lappend lucky $n circle $w [$w bbox $n] red update idletasks #after 500 after 100 } set lucky [lsort -integer $lucky] #circle $w [$w bbox [ldraw numbers]] yellow set n [ldraw numbers] lappend lucky $n circle $w [$w bbox $n] yellow $w lower marked puts -nonewline "[ format "%3d: " $DrawNr ]" for {set i 0} {$i<=6} {incr i} { puts -nonewline "[format [expr {$i==6 ? "- %2d" : "%2d "}] [lindex $lucky $i] ]" } puts "" # Todo: Compare draw to own tip } proc circle {w coords color} { $w create oval $coords -fill {} -outline $color -width 2 -tag 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} #---------------------------------------------------- set DrawNr 0 catch {console show} puts "Lotto" main if 0 { ---- [HJG] Now it would be nice to see how many draws would be required to get a jackpot :-) but I have trouble to identify the numbers under the mouse-cursor... [Rs] I would prefer if people discussed changes, rather than just putting them in - this page was also meant as an example of simplicity, and isn't any more :( ---- [Category Toys] - [Arts and crafts of Tcl-Tk programming] }