首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery Easing函数

Jquery Easing函数
EN

Stack Overflow用户
提问于 2011-02-06 10:20:02
回答 1查看 1.4K关注 0票数 0

我正在研究在java应用程序中使用的jquery java函数,并以此作为结束:

代码语言:javascript
复制
// t: current time, b: begInnIng value, c: change In value, d: duration
    float easeInOutQuad (float x, float t, float b, float c, float d) {
        if ((t/=d/2) < 1) return c/2*t*t + b;
        return -c/2 * ((--t)*(t-2) - 1) + b;
    }

有人能教我如何把这个插入到我的动画球体运动中吗?

编辑:我不会在这里放不必要的代码来描述我的球体移动。想象一个球体,它的X位置名为X,它将使用这个缓动函数从0到1000。我如何提供函数?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-06 12:02:23

这基本上是psuedo-java代码,但我测试了它,它可以工作。我画了一个小圆,而不是用球体:

代码语言:javascript
复制
Sphere sphere = new Sphere();

// you might want these to be in the sphere class
float begin;
float change;
float time;
long start;
float duration;
float destX = 200;

// setup, do this when you want to start the animation
void init(){
  begin = sphere.x;
  change = destX - begin;
  time = 0;
  start = System.currentTimeMillis();
  duration = 1000;
}

// loop code, may also be where you render the sphere
void loop(){
  if (time <= duration){
    sphere.x = easeInOutQuad(time, begin, change, duration);
  }else{
    // animation is over, stop the loop
  }
  time = System.currentTimeMillis() - start;
  sphere.render();
}

float easeInOutQuad (float t, float b, float c, float d) {
  if ((t/=d/2) < 1) return c/2*t*t + b;
  return -c/2 * ((--t)*(t-2) - 1) + b;
}

class Sphere{
  float x = 0;
  void render(){
    ellipse(x, 100, 10, 10);
  } 
}

你可能想要根据你的设置来移动东西,但是这就是你如何使用这种放松方程的方式。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4911096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档