如何使用处理语言创建3d块网格?

时间:2016-02-03 16:50:24

标签: 3d processing visualization

我需要使用处理语言创建不同高度的3D块网格。

现在我陷入了这个输出: 3D block grid with varying height(Current Output)

以上输出的代码:

import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
import peasy.test.*;
import processing.serial.*;

PeasyCam cam;


//float i1,i2,i3;


void setup() {
  size(800, 800, P3D);
    //smooth(4);
   cam = new PeasyCam(this, 200);
  cam.setMinimumDistance(100);
  cam.setMaximumDistance(200);
}

void draw() {
    background(200);
    randomSeed(30);

    for(int x=-50;x<=50;x+=18)
    {
       for(int y=-50;y<=50;y+=18)
          {

               pushMatrix();
               translate(x,y,0);

               boxT();


               popMatrix();
          }

    }
  }

void boxT()
{
  fill( random(255), random(255), random(255), random(255)); 
  strokeWeight(4);
  translate(0,0,0);
   box(10,10,random(50));  

}

现在,我想要的输出是这些具有不同高度但具有公共基准面的3D块,如下所示: 3D block grid with varying heights(Desired Output)

提前致谢!

1 个答案:

答案 0 :(得分:0)

处理从框的中心绘制

如果你想在同一点画出盒子的底部,你必须将盒子宽度的一半向上翻转。

请注意,此行不执行任何操作:

translate(0,0,0);

相反,您需要将z轴的宽度翻译为此处框的宽度的一半。