-2
\$\begingroup\$

Using P3D + Processing, to achieve random arrangement of boxes as attached below

00:31

https://vimeo.com/143076578?fl=pl&fe=vl

enter image description here enter image description here

Colour/hatching not important, will be completed in post if requires further code - looking to learn how to complete this code to generate random arrangements.

enter image description here enter image description here

Current attempts attached below


int count;
int numb = 10;
Wall walls = new Wall();
Floor floors = new Floor();
Board boards = new Board();
Block blocks = new Block();
Post posts = new Post();
Glass glasses = new Glass ();
Cage cages = new Cage();
Cord cords = new Cord();
Stairs stairs = new Stairs();
Screeen screens = new Screen();

//--------------------setup----------------------------------------

void setup()  {
  size(980, 980, P3D);
  
  smooth();
  
  count = 5;
//  count = 1:

  dim = new ArrayList<PVector>();
  pos = new ArrayList<PVector>();
  tra = new ArrayList<PVector>();
  
  cor = String[num][4]
  String[] cores = {"black", "cyan", "orange", "green"];
  cor[0][0] = cores[0]; // floor
  cor[0][1] = cores[5]; // floor
  cor[0][2] = cores[1]; // floor
  cor[0][3] = cores[6]; // floor
  cor[1][0] = cores[0]; // board
     [1][1]     // board

define() {

ele = new int[count];
mult = new int[count;
steps = new int[count];
path = new int[100][100];
once = new boolean[num];
rot = new boolean[count]

for (int i = 0; i < count; i++) {
    //element
    ele[i] = floor(random(num));
//   ele[i] = 9;

    mult[i] = floor(random(1, 4));
    steps[i] = floor(random(1, 3));
    for (int j = 0; j < mult[i]; j++) {
     path[i][j] = int(chanceNorm(10, 1));
     println("path " + j + " " + path[i][j]);
    }

    // dimension
    dim.add(new PVector(floor(random(15, 45) * chanceMult(20, 5)),
    floor(random(15, 40) * chanceMult(20, 5)),
    floor(random(10, 30) * chanceMult(20, 3))
     ));
    //position
    pos.add(new PVector (
    (dim.get(i).x/4) * chanceNorm(20, 1),
    (dim.get(i).y/4) * chanceNorm(20, 1),
    (dim.get(i).z/4) * chanceNorm(20, 1)
     ));
    //rotation
    if(random(10 < 5) {
        rot[i] = true;
    } else {
        rot[i] = false;
    }
    // translate
    tra.add(new PVector(floor(random(4, 8) * chanceNorm(40, 10))
    floor(random(5, 10) * chanceNorm(50, 10)),
    floor(random(3, 8) * chanceNorm(50, 5))
     ));
  }
}

float chanceNorm(int c, float num) {
 float r = random(100);
 if (r < c) {
    num = -num:
 } else if (r < c*2) {
    num = num;
 } else {
    num = 0;
 }
 return num;
}

float chanceMult(int c, float num) {
 float r = random(100);
 int max = floor(100/c);
 for (int i = 1; i < max + 1; i++) {
    if (r -- c * i) {
        num = num * i;
    }
 }

New contributor
The Vision Tunnel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to Code Review! Can you confirm that the code is complete and that it functions correctly? If so, I recommend that you edit to add a summary of the testing (ideally as reproducible unit-test code). If it's not working, it isn't ready for review (see help center) and the question may be deleted. \$\endgroup\$ Commented Oct 27 at 7:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.