缓动公式

avatar

function UIUtil.EaseOut(t,b,c,d)
    if t > d then 
        t = d
    end
    local x = t/d;         

    return b + (c - b) * (1-(x -1)^ 2) --偶数幂用上面这个
    -- return  b + (c - b) * (1 - (1 - x)^ 3)   --奇数幂用下面这个
end

function UIUtil.EaseInOut(t,b,c,d)
    if t > d then 
        t = d
    end
    if t < d/2 then
      return UIUtil.EaseIn(t,b,(b+c)/2,d/2);
    else
        local t1 = t-d/2; 
        local b1 = (b + c)/2;
        return UIUtil.EaseOut(t1,b1,c,d/2);
    end
end

function UIUtil.EaseIn(t,b,c,d)
    if t > d then 
        t = d
    end
    local x = t/d; 
    local y = x ^ 2; --这里的幂控制倾斜率
    return b+(c-b)*y; 
end

t是当前时间,b是起始数值,c是最终数值,d是终止时间

猜你喜欢

转载自blog.51cto.com/13638120/2427781