Arraylist in a draw function

allow me to show you just a rewrite,
not say it is better, but for me, easy readable:

import oscP5.*; 
OscP5 oscP5;

float ramp1=450, ramp2=100, ramp3=1;
ArrayList<Polygon> polygons;
PShape boxes;
int many = 200;  // number of boxes in array

void setup() {
  //fullScreen(P3D);
  size(1000, 1000, P3D); 
  oscP5 = new OscP5(this, 12000);
  make_boxes();
  polygons = new ArrayList<Polygon>();  // Make an ArrayList
  for (int i = 0; i < many; i++)   polygons.add(new Polygon(boxes));
}

void draw() {
  background(255);
  draw_sphere();
  for (Polygon poly : polygons)   poly.display();// move and display them all
}

void oscEvent(OscMessage theOscMessage) {    
  float value = theOscMessage.get(0).floatValue();
  if (theOscMessage.checkAddrPattern("/ramp1")) {
    if (value > 0.1)   ramp1 = value;
    else               ramp1 = 0.0;
  }
  float value2 = theOscMessage.get(0).floatValue();
  if (theOscMessage.checkAddrPattern("/ramp2")) {
    if (value2 > 0.1)  ramp2 = value2;
    else               ramp2 = 0.0;
  }
  float value3 = theOscMessage.get(0).floatValue();
  if (theOscMessage.checkAddrPattern("/ramp3")) {
    if (value3 > 0.1)  ramp3 = value3;
    else               ramp3 = 0.0;
  }
}

void draw_sphere() {
  stroke(0);               //  for the sphere
  strokeWeight(ramp3);
  translate(width/2, height/2, 0);
  //rotateX(mouseY * 0.05);
  rotateY(radians(ramp2));
  noFill();
  sphereDetail(30);
  sphere(ramp1);
  println(ramp1); 
}

  //dimentions of base are 30X by 20 deep // sides are 50 Y by 30 X
int bw = 50, bw2 = 2*bw, bw3 = 3*bw, bh = 20, bh2 = 40, bh3 = 70, bz = 20;

void make_boxes() {
  boxes = createShape();   //boxes is the name of my shape  
  boxes.beginShape();
  boxes.strokeWeight(1);
  boxes.stroke(0);
  boxes.noFill();

  boxes.vertex(bw, bw, 0);    // this is the square top
  boxes.vertex(bh, bw, 0); 
  boxes.vertex(bh, bw, -bz); 
  boxes.vertex(bw, bw, -bz); 
  boxes.vertex(bw, bw, 0); 

  boxes.vertex(bh3, bw2, 0);   //front rectangle
  boxes.vertex(bh2, bw2, 0); 
  boxes.vertex(bh, bw, 0); 

  boxes.vertex(bh, bw, -bz); //back rectangle
  boxes.vertex(bh2, bw2, -bz); 
  boxes.vertex(bh3, bw2, -bz); 
  boxes.vertex(bw, bw, -bz); 

  boxes.vertex(bw, bw, -bz);  //close up bottom or middle square
  boxes.vertex(bh3, bw2, -bz); 
  boxes.vertex(bh3, bw2, 0); 
  boxes.vertex(bh3, bw2, 0);   
  boxes.vertex(bh2, bw2, 0);
  boxes.vertex(bh2, bw2, -bz); 

  boxes.vertex(bh2, bw2, -bz);    //bottom back rectangle
  boxes.vertex(bh, bw3, -bz); 
  boxes.vertex(bw, bw3, -bz); 
  boxes.vertex(bh3, bw2, -bz); 

  boxes.vertex(bh3, bw2, 0);   //front bottom rectangle
  boxes.vertex(bw, bw3, 0);
  boxes.vertex(bh, bw3, 0); 
  boxes.vertex(bh2, bw2, 0);   

  boxes.vertex(bh, bw3, 0);   //bottom square
  boxes.vertex(bh, bw3, -bz); 
  boxes.vertex(bw, bw3, -bz); 
  boxes.vertex(bw, bw3, 0); 

  boxes.endShape();
}

// A class to describe a Polygon (with a PShape)
class Polygon {
  PShape s;              // The PShape object
  float x, y, z;         // The location where we will draw the shape
  float speed;           // Variable for simple motion

  Polygon(PShape s_) {
    x = random(-1000, 1000);
    y = random(1000, -1000); 
    z = random(-1000, 1000); 
    s = s_;
    speed = random(-1, 1);
  }

  // Simple motion
  void move() {
    y += speed;
    x += speed*1.2;
    z += speed*4;
    if (y > height)  y = -100;
    if (y < -1000)   y = height;
    if (x > width)   x = 0;
    if (x > width)   x = -200;
    if (z > 0)       z = -500;
    if (z < -1000)   z = 0;
  }

  void display() {    // Draw the object
    pushMatrix();
    move();
    translate(x, y, z);
    shape(s);
    popMatrix();
  }
}

your question:
-a- number of elements in array list ( at runtime?)
you can make the whole array again, or just change the number you draw,
also can make a visible attribute in the class and use it inside display()
and write it ( show / hide ) on certain conditions.

-b- if the elements ( boxes shape ) need to be different,
they ( their size parameters ) need to be part of the class
and not like now ONE global shape.
BUT depending what you want to do, still there are ways to show ONE global shape in different ways, size, fill- stroke - color, angle …
https://processing.org/reference/PShape.html

-c- the variables ( here global ) for the boxes shape i give you already,
you could make them “knowledge” of the class to make each one different

2 Likes