Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用JS进行三维渲染_Javascript_Colors_3d - Fatal编程技术网

Javascript 用JS进行三维渲染

Javascript 用JS进行三维渲染,javascript,colors,3d,Javascript,Colors,3d,我有一个移动立方体的3D渲染,它们是不同的颜色,所以它就像彩虹。但是我想知道是否有一种方法可以让方块产生脉冲颜色。 色彩模式(HSB,nums.x*nums.y,1,1)是您的答案。 在更新函数中应用它,并通过改变'nums.x*nums.y'值来调整颜色 使用计时器或简单的勾号(您只需在更新函数中执行tick++)作为修改器,直到达到某个迭代,然后重置(或跳转值)。你应该会得到想要的效果。好的。。很明显,我在拖延,最后一个小时都在和你的回复玩 这可能不完全是你想要的,但也许会对你有所帮助

我有一个移动立方体的3D渲染,它们是不同的颜色,所以它就像彩虹。但是我想知道是否有一种方法可以让方块产生脉冲颜色。
色彩模式(HSB,nums.x*nums.y,1,1)
是您的答案。 在更新函数中应用它,并通过改变'nums.x*nums.y'值来调整颜色


使用计时器或简单的勾号(您只需在更新函数中执行
tick++
)作为修改器,直到达到某个迭代,然后重置(或跳转值)。你应该会得到想要的效果。

好的。。很明显,我在拖延,最后一个小时都在和你的回复玩

这可能不完全是你想要的,但也许会对你有所帮助

  class Cube {
    constructor(x_, y_, z_, size_, offset_) {
    this.x = x_;
    this.y = y_;
    this.z = z_;
    this.size = size_;
    this.offset = offset_;
    this.angle = 0;
    
    this.tick = 1;   // starting point
    this.hueSpeed = 2;   // tick modifier
  }

  
  update(f) {
    this.y = map(f(this.angle + this.offset), -1, 1, this.size / 2, height - this.size / 2);
    this.angle += 0.05;
    colorMode(HSB, this.tick, 1, 1);

    /** 
    * The request is there to simply regulate the frequency of the tick a bit.. 
    * Though we do need to cancel the previous request if hadn't yet fired
    * Which I'm apparently to lazy to do atm
    */
    window.requestAnimationFrame((e)=>{
      this.tick += this.hueSpeed;
      (this.tick > 150 || this.tick < 2) && (this.hueSpeed *= -1);
    });
  }

  render() {
    push();
    stroke(0);
    translate(this.x, this.y, this.z);
    box(this.size);
    pop();
  }
}
类多维数据集{
构造函数(x、y、z、大小、偏移){
这个.x=x;
这个。y=y;
这个.z=z;
this.size=size_u2;;
this.offset=offset_u2;;
这个角度=0;
this.tick=1;//起点
this.hueSpeed=2;//勾号修饰符
}
更新(f){
this.y=map(f(this.angle+this.offset),-1,1,this.size/2,height-this.size/2);
该角度+=0.05;
颜色模式(HSB,this.tick,1,1);
/** 
*这个请求只是简单地调节一下滴答声的频率。。
*虽然我们需要取消之前的请求,如果我们还没有启动
*很明显,我懒得用自动取款机取款
*/
window.requestAnimationFrame((e)=>{
this.tick+=this.hueSpeed;
(this.tick>150 | | this.tick<2)和&(this.hueSpeed*=-1);
});
}
render(){
推();
冲程(0);
翻译(这个.x,这个.y,这个.z);
盒子(这个尺寸);
pop();
}
}
这是cube.js脚本文件,是唯一被修改的文件