2016-02-03 103 views
0

我需要使用處理語言創建具有不同高度的3D塊網格。如何使用處理語言創建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)

在此先感謝!

回答

0

處理從盒子中心處吸取盒子

如果要在同一點處繪製框的底部,則必須將框的寬度向上翻轉一半。

請注意,此行不會做任何事情:

translate(0,0,0); 

相反,你會想在這裏框的寬度的一半,以z軸平移。