# How to make Grid out of Boxes (3D)

**URL:** https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070
**Category:** Coding Questions
**Created:** [February 25, 2021, 1:30am UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070 "2021-02-25T01:30:17Z")
**Posts on this page:** 10
**Page:** 2

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [February 26, 2021, 2:03pm UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/21 "2021-02-26T14:03:11Z")

</div>

> [@paulgoux](#):
>
> currently only the menu’s work. Again there is code for everything else, but I have to sort the button logic,

great and nice working

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [February 26, 2021, 10:07pm UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/22 "2021-02-26T22:07:17Z")

</div>

> [@Chrisir](#):
>
> We can make it so that you can click each box with the mouse and drag the mouse to change the height of the box
> 
> Or by keyboard

with keyboard in-order to add all variable when you have a time make it if it dose not bother you

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 27, 2021, 6:26am UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/23 "2021-02-27T06:26:41Z")

</div>

> [@jafal](#):
>
> with keyboard in-order to add all variable

Can you please tell me more?

Do you mean click cube by mouse and change with keys?

I am on a journey now, maybe Monday

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [February 27, 2021, 6:29am UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/24 "2021-02-27T06:29:54Z")

</div>

> [@Chrisir](#):
>
> Can you please tell me more?
> 
> Do you mean click cube by mouse and change with keys?
> 
> I am on a journey now, maybe Monday

all with keyboard as menu when you finish it i am going to try to replace the keyboard with sliders

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [February 27, 2021, 6:33am UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/25 "2021-02-27T06:33:26Z")

</div>

> [@Chrisir](#):
>
> I am on a journey now, maybe Monday

have fun no matter when you have time it is fine 😘 😘

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 27, 2021, 7:13am UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/26 "2021-02-27T07:13:27Z")

</div>

> [@jafal](#):
>
> all with keyboard

How selection a cube with keyboard?

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [February 27, 2021, 7:15am UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/27 "2021-02-27T07:15:24Z")

</div>

> [@Chrisir](#):
>
> How selection a cube with keyboard?

within its number in the cell

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 1, 2021, 11:50am UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/28 "2021-03-01T11:50:30Z")

</div>

Here is an example.

- You can click cursor left / right to select a cube

- You can click cursor up/ down to change the height of the selected cube

- You can click 0…9 to select cube number directly.

Chrisir

```auto
Cube[] cubes;

float angle1; 

int [][] gridHeight = {
  { 1, 2, 3, 4 }, 
  { 8, 7, 6, 5 }, 
  { 8, 2, 8, 2 }, 
  { 1, 2, 3, 4 }
};  

int selected; 

void setup() { 
  size(1600, 960, P3D);

  int unit = 90; 
  int count; 

  int rows = 4; 
  int columns = 4;

  count = rows * columns; // wideCount * highCount * depthCount; 
  cubes = new Cube[count];

  // setting up the grid 
  int index = 0; 
  for (int z = 0; z < rows; z++) {
    //for (int y = 0; y < highCount; y++) { 
    for (int x = 0; x < columns; x++) { 
      cubes[index++] = new Cube(
        x*unit-(4*unit), // X
        0, // Y 
        z*unit-(5*unit), // Z  
        30*gridHeight[x][z], 
        true); // visible
    }
    // }
  }
}

void draw() { 
  background(0); 
  lights();

  translate (width/2, height/2+90, -330);

  //rotateX(-0.4); 
  //rotateZ(angle1); 
  //angle1+=0.004;

  rotateY(map(mouseX, 0, width, -TWO_PI, TWO_PI));
  rotateX(-map(mouseY, 0, height, -TWO_PI, TWO_PI));

  for (int i = 0; i < cubes.length; i++) { 
    if (i==selected) 
      cubes[i].display(true);
    else 
    cubes[i].display(false);
  }
}

void keyPressed() {
  if (key==CODED) {

    switch(keyCode) {
      //
    case UP: 
      cubes[selected].heightCube+=10; 
      break; 

    case DOWN:
      cubes[selected].heightCube-=10;
      break;

    case LEFT:
      selected--;
      if (selected<0) 
        selected=cubes.length-1; 
      break; 

    case RIGHT:
      selected++;
      if (selected>cubes.length-1) 
        selected=0; 
      break;
    }

    return;
  }

  // ---

  if (key>='0'&&key<='9') {
    selected = int(key+"");
  }
}

// ==============================================================================================================

class Cube { 
  int posX; 
  int posY; 
  int posZ; 

  color col = color(255, 0, 0); // color(random(255), random(255), random(255));
  boolean exist = false; 

  float sizeCube = 90;

  float heightCube = 10 + int(random(1) * 300); 

  // Contructor 
  Cube(int xOffsetTemp, int yOffsetTemp, int zOffsetTemp, 
    float d, 
    boolean existTemp) { 
    posX = xOffsetTemp; 
    posY = yOffsetTemp;
    posZ = zOffsetTemp;

    heightCube = d;  

    exist = existTemp;
  }// Contructor 

  // Custom method for drawing the object 
  void display( boolean isSelected) { 
    if (exist) {
      stroke(0); 

      if (isSelected) 
        fill(0, 255, 0);
      else
        fill(col);

      pushMatrix();
      translate(posX, posY + heightCube/2, posZ);
      box(sizeCube, sizeCube + heightCube, sizeCube);
      popMatrix();
    }//if
  }//method
  //
} //class
//

```

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [March 1, 2021, 2:29pm UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/29 "2021-03-01T14:29:42Z")

</div>

@[Chrisir](https://discourse.processing.org/u/Chrisir)  
thanks for you and thanks for your time

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [March 1, 2021, 2:59pm UTC](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070/30 "2021-03-01T14:59:14Z")

</div>

@ [Chrisir](https://discourse.processing.org/u/Chrisir)  
I keep tracking your posts with previous versions of the forum. Always you have cooperation and help others. I saw you comments that span many years ago.

Bless you and grateful for your continuous efforts

[Previous page](https://discourse.processing.org/t/how-to-make-grid-out-of-boxes-3d/28070.md?page=1)
