Version 2 of Lotto

Updated 2005-06-03 06:20:23

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*$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} {
        circle $w [$w bbox [ldraw numbers]] red
        update idletasks
        after 500
    }
    circle $w [$w bbox [ldraw numbers]] yellow
    $w lower marked
 }
 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}

#----------------------------------------------------

 main

if 0 {


Category Toys - Arts and crafts of Tcl-Tk programming }