proc strobe {w x0 y0 x1 y1 color} { set color2 [color'dim $color 0.95] set bgcolor [color'dim $color 0.66] set id [$w create rect $x0 $y0 $x1 $y1 -fill $bgcolor] set dx [expr {($x1-$x0)/3.}] set x2 [expr {$x0+$dx}] set x3 [expr {$x0-2*$dx}] foreach i {0 1 2} { $w create arc $x0 $y0 $x1 $y1 -style chord \ -start 115 -extent 130 -fill $color2 \ -outline $color2 -tag [list L$i.$id X.$id]] $w create rect $x0 $y0 $x2 $y1 -fill $color \ -outline $color -tag [list M$i.$id X.$id] $w create arc $x3 $y0 $x2 $y1 -style chord \ -start 295 -extent 130 -fill $color2 \ -outline $color2 -tag [list R$i.$id X.$id] if $i { foreach shape {L M R} { $w move $shape$i.$id [expr {$dx*$i}] 0 } } } strobe'animate $w $id {R0 {M0 R1} {L0 M1 R2} {L1 M2} L2} }if 0 {The animation happens by lowering all these items below the cover, then raising a set of items (specified as a "phase" in a "script") above it, so they become visible. The script is then cycled, so the first item is moved to the end of the script, and after some interval this repeats again - normally I love to use the every timer, but then the script would have to be in a global variable to survive. With the solution below, the script is strictly encapsulated in the after calls.}
proc strobe'animate {w id phases} { $w raise $id set phase [lindex $phases 0] foreach tag $phase {$w raise $tag.$id} set phases [concat [lrange $phases 1 end] [list $phase]] after 100 [list strobe'animate $w $id $phases] }#-- making a color darker by a certain factor:
proc color'dim {color factor} { foreach {rmax gmax bmax} [winfo rgb . white] break ;# "calibration" foreach {r g b} [winfo rgb . $color] break foreach var {r g b} { set $var [expr {round([set $var]*$factor*255./[set ${var}max])}] } format #%02X%02X%02X $r $g $b }if 0 {Now testing with two instances, to verify they don't interfere:}
pack [canvas .c -width 100 -height 50] strobe .c 10 10 40 40 blue strobe .c 60 10 90 40 orange#-- Little dev helpers:
bind . <Escape> {exec wish $argv0 &; exit} bind . <F1> {console show}if 0 {
Category Animation - Arts and crafts of Tcl-Tk programming }