Tcl
tween.tcl


return to misc index



This script implements a simple but handy inbetweening procedure. For information about 'tweening refer to inbetweening.


Listing 1


proc tween {k1 k2 frame v1 v2 rateOfChange} {
if {$frame < $k1} {
   set output $v1
} elseif {$frame > $k2} {
   set output $v2
} else {
   set percent double([expr $frame - $k1])
   set percent [expr $percent / [expr $k2 - $k1]]
   set percent [expr pow($percent, $rateOfChange)]
   set output [expr [expr [expr $v2 - $v1] * $percent] + $v1]
   }
return $output
}


The input parameters are:

tween
    k1           the key frame at which the tweening should start
    k2           the key frame at which the tweening should end
    v1           value at key frame 1
    v2           value at key frame 2
    rateOfChange 1.0 for linear, 
                 0.5 for deacceleration or 
                 2.0 for acceleration
Example:
    # print a 'tweened value to the console
    puts "value at frame 7 is [tween 5 30 7 0.5 2.5 1.0]"
                 
                 
                 



© 2002- Malcolm Kesson. All rights reserved.