Bubbles

Source code:


# ----------------------------------------------------------------
# Creating bubbles - Demo of the canvas widget
#  Freely distributable under the "Standard Tcl License"
#  See http://www.eolas.com/tcl/license.txt for details
# ----------------------------------------------------------------


# ----------------------------------------------------------------
# Canvas widget
# ----------------------------------------------------------------


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

# ----------------------------------------------------------------
# Creates oval objects and places them on canvas
# ----------------------------------------------------------------

for {set i 0} {$i < 5} {incr i} {
	set x_position [expr 10 * $i + 50] 
	.c create oval $x_position 20  \
		 [expr $x_position + 10] 30 \
		-tags m$i -outline purple
	}

for {set i 0} {$i < 5} {incr i} {
	set x_position [expr 20 * $i + 50] 
	set tag m[expr $i +5]
	.c create oval $x_position 30 \
		[expr $x_position + 20] 50 \
		-tags $tag -outline red 
	}


# ----------------------------------------------------------------
# Moves object from one place to another, then back to original
# position
# ----------------------------------------------------------------


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_bubbles { w x y d } {
for {set i 0} {$i < 1000} {incr i $d} {
after $i "nervous $w $x $y" 
}
after $i [list nervous_bubbles $w $x $y $d]
}


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


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

nervous_bubbles m5 4 6 600 
nervous_bubbles m6 -9 3 200 
nervous_bubbles m7 -7 -5 400 
nervous_bubbles m8 8 4 200 
nervous_bubbles m9 6 -2 700 
 
pack .c