帮助制定一个三次缓和方程 [英] Help formulating a cubic easing equation

查看:103
本文介绍了帮助制定一个三次缓和方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

int steps = 10;
for (int i = 0; i <= steps; i++) {
    float t = i / float(steps);
    console.log( "t  " + t );
}

这样可以使数字成为线性方式,如{0,0.1,0.2 ,...,0.9,1.0}我想应用立方(in或out)缓动方程,以便输出数字逐渐增加或减少

That out puts numbers in a linear fashion like this { 0, 0.1, 0.2, ..., 0.9, 1.0 } I would like apply the cubic (in or out) easing equation so the output numbers increase or decrease gradually

更新

不确定我的实施是否正确,但我的曲线符合预期

Not sure if my implementation if correct but I am getting curve as expected

float b = 0;
float c = 1;
float d = 1;
for (int i = 0; i <= steps; i++) {
    float t = i / float(steps);

    t /= d;

    float e = c * t * t * t + b;

    console.log( "e  " + e );
    //console.log( "t  " + t );
}


推荐答案

EasIn Cubic函数



EasIn Cubic Function

/**
 * @param {Number} t The current time
 * @param {Number} b The start value
 * @param {Number} c The change in value
 * @param {Number} d The duration time
 */ 
function easeInCubic(t, b, c, d) {
   t /= d;
   return c*t*t*t + b;
}



EaseOut Cubic函数



EaseOut Cubic Function

/**
 * @see {easeInCubic}
 */
function easeOutCubic(t, b, c, d) {
   t /= d;
   t--;
   return c*(t*t*t + 1) + b;
}

在这里你可以找到其他有用的公式: http://www.gizma.com/easing/#cub1

Here you can find othere useful equations: http://www.gizma.com/easing/#cub1

把这段代码放一段时间,就像你以前一样,你的输出立方数会减少。

Put this code in a while, as you've don before and you will have your output cubic decreasing numbers.

这篇关于帮助制定一个三次缓和方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆