Quantcast
Channel:
Viewing all articles
Browse latest Browse all 27

Concisely animating a local T value along a path

$
0
0

If you have a T value, in the range of [0.0-1.0] you can convert that to a local T value for each part of that curve.

    var rangePerItem = 1.0 / items.length;
    var t = 0.73;
 
    for(var i = 0; i < items.length; i++) {
        // determine which piece of the line this item falls into
        var a          = i * rangePerItem;
        var b          = (i + 1) * rangePerItem;
 
        // normalize the value so that 0.51 on the third one becomes 1.0 for the first and second, and 0.2 for the third, and 0 for the 4th
        var localT     = (t - a) / (b - a);
        localT = clamp(localT, 0, 1);
        item.update(localT);
    }

Viewing all articles
Browse latest Browse all 27

Trending Articles