# # Package to make things blink # namespace eval ::Blinker:: { # Array of running blinking things variable blinkers array set blinkers {} # number of blinkers variable num_blinkers 0 # Makes "atomsel" atoms blink every "interval" seconds # (defaults to 1) # Molid (defaults to "top") # Display blinking with "rep" representation" (defaults to # "newcartoon") # Returns -1 if it can't start the blinking proc blink {atomsel {interval 2} {molid "top"} {rep "NewCartoon"} {color "Structure"}} { variable num_blinkers variable blinkers # Add a new rep to the molecule mol addrep $molid set new_rep [expr [molinfo $molid get numreps]-1] if { [catch {mol modselect $new_rep $molid "$atomsel"} thing] } { # Failed to correctly select, abort mol delrep $new_rep $molid return -1 } mol modstyle $new_rep $molid $rep mol modcolor $new_rep $molid $color puts $num_blinkers set blink_id [incr num_blinkers] array set blinkers [list $blink_id:molid $molid] array set blinkers [list $blink_id:repid $new_rep] array set blinkers [list $blink_id:state 1] array set blinkers [list $blink_id:interval [expr $interval*1000]] array set blinkers [list $blink_id:after -1] # start up blinking; return blink_id return [doBlink $blink_id] } proc doBlink {blink_id} { variable num_blinkers variable blinkers if { $blinkers($blink_id:state) == 0 } { mol showrep $blinkers($blink_id:molid) $blinkers($blink_id:repid) on set blinkers($blink_id:state) 1 } elseif { $blinkers($blink_id:state) == 1 } { mol showrep $blinkers($blink_id:molid) $blinkers($blink_id:repid) off set blinkers($blink_id:state) 0 } set blinkers($blink_id:after) [after $blinkers($blink_id:interval) "[namespace current]::doBlink $blink_id"] } # Stops the blinking of a particular blink_id proc stopBlink {blink_id} { variable num_blinkers variable blinkers after cancel $blinkers($blink_id:after) mol delrep $blinkers($blink_id:repid) $blinkers($blink_id:molid) array unset blinkers "$blink_id*" } }