Nervous text

Source code:



# ----------------------------------------------------------------
# Nervous text demo of the canvas widget
#  
#  Freely modifiable/redistributable under the "Standard Tcl License"
#  See http://www.eolas.com/tcl/license.txt for details
# ----------------------------------------------------------------



# ----------------------------------------------------------------
# Moves an object from one place to another
# ----------------------------------------------------------------

proc nervous { w x y } {
	.c move $w $x $y
	after 100 ".c move $w [expr -$x] [expr -$y]"
	}


# ----------------------------------------------------------------
# Continually calls the nervous procedure 
# ----------------------------------------------------------------

proc nervous_text { w x y d } {
	for {set i 0} {$i < 1000} {incr i $d} {
	after $i "nervous $w $x $y" 
		}
	after $i [list nervous_text $w $x $y $d]
}

# ----------------------------------------------------------------
# Creates the canvas 
# ----------------------------------------------------------------

canvas .c -bg white -width 200 -height 75
pack .c

# ----------------------------------------------------------------
# Creates the text objects
# ----------------------------------------------------------------

set word1 "Hello"
set wordlist_1 [split $word1 {}]

for {set i 0} {$i < [llength $wordlist_1]} {incr i} {
	set letter  [lindex $wordlist_1 $i]
	set x_position [expr 10 * $i + 50] 
	.c create text $x_position 20 -text $letter \
		-tags m$i -fill purple
}

# ----------------------------------------------------------------
# Creates the text objects for the second word
# ----------------------------------------------------------------

set word2 "World"
set wordlist_2 [split $word2 {}]

for {set i 0} {$i < [llength $wordlist_1]} {incr i} {
	set letter  [lindex $wordlist_2 $i]
	set x_position [expr 10 * $i + 100] 
	set tag m[expr $i +5]
	.c create text $x_position 50 -text $letter  \
		-tags $tag -fill red
	}

# ----------------------------------------------------------------
# Calls the procedure for each text object
# ----------------------------------------------------------------

nervous_text m0 5 5 500
nervous_text m1 3 2 300
nervous_text m2 4 -6 700
nervous_text m3 -4 -3 600
nervous_text m4 -7 5 200 

nervous_text m5 4 6 600 
nervous_text m6 -9 3 200 
nervous_text m7 -7 -5 400 
nervous_text m8 8 4 200 
nervous_text m9 6 -2 700