gpt4 book ai didi

javascript - 帮助制定三次缓动方程

转载 作者:行者123 更新时间:2023-11-29 09:58:16 26 4
gpt4 key购买 nike

我有如下一段代码

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 } 我想应用三次(进或出)缓动方程,使输出数字逐渐增加或减少


更新

不确定我的实现是否正确,但我得到了预期的曲线

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 三次函数

/**
* @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 三次函数

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

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

将此代码放入一段时间,就像您之前所做的那样,您将得到输出立方递减的数字。

关于javascript - 帮助制定三次缓动方程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7346805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com