P5js

时间:2017-01-22 18:56:41

标签: loops interpolation p5.js lerp

我正在尝试在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

0 个答案:

没有答案