LJ Archive

Listing 1: Tcl/Tk Animation Script

#!/usr/local/bin/wish

global name frames dir

# Set name to the base filename of the images, i.e. mb
# for mb01.ppm, mb02.ppm, mb03.ppm, etc...
# set name mb

set dir forward
proc forward {} {
  global name frames dir
  set dir backward

  for { set i 1 } { $i <= $frames } { incr i } {
    set n [ format "%02d" $i ]
    .t configure -image ${name}${n}
    update idletasks
  }
}

proc backward {} {
  global name frames dir
  set p forward

  for { set i $frames } { $i >= 1 } { incr i -1 } {
    set n [ format "%02d" $i ]
    .t configure -image ${name}${n}
    update idletasks
  }
}

set frames 1
while 1 {
  set n [ format "%02d" $frames ]
  image create photo mb$n
  if { [ catch {eval ${name}$n read ${name}${n}.ppm} ] } { break }
  incr frames
}
incr frames -1
puts "Loaded $frames images"

label .t -image ${name}01
pack .t
bind .t <Button-1> { eval $dir }
LJ Archive