0

我正在尝试在 p5js 中创建多个插值,为此我尝试在 javaScript 中重新创建 Ben Fry 的 Integrator 类。我意识到从处理到 p5js 的转换和转换非常困难,所以如果这是不可能的,如果你给我提示以另一种方式做这件事,我将不胜感激。谢谢你。

这是我到目前为止所做的。. .

   function Integrator(value, damping, attraction)
{
  this.DAMPING=0.5;
  this.ATTRACTION=0.2;

  this.value;
  this.vel;
  this.accel;
  this.force;
  this.mass=1;

  this.damping=this.DAMPING;
  this.attraction=this.ATTRACTION;

  this.targeting; //boolean
  this.target;

  this.value=value;
  this.damping=damping;
  this.attraction=attraction;

  this.set =function(v)
  {
    this.value=v;
  }

  this.update = function()
  {
    if(this.targeting)
    {
      this.force +=this.attraction *(this.target-this.value);
    }

    this.accel = this.force/this.mass;
    this.vel = (this.vel+this.accel)*this.damping;
    this.value +=this.vel;

    this.force=0;
  }

  this.target = function(t)
  {
    this.targeting=true;
    this.target=t;
  }

  this.noTarget = function()
  {
    this.targeting = false;
  }

}

这里也是 Ben Fry http://benfry.com/writing/map/Integrator.pde的原始处理代码的链接

4

0 回答 0