Hi,
I am really new to processing. I am controlling my animations using OSC messages. I altered some code from one of the “create shapes” examples and I want to be able to control the number of items in an array list. I also want to be able to change the dimensions in the Pshape I made (called boxes), which is what is in the ArrayList. I would think that the create new ArrayList code would need to be in void draw() so I could use a variable and I could change it. As well as the code between beginShape() and endShape() so I could have variables for the verticies I want to change the dimensions to.
Right now I have those things in void setup(). If I put them in draw they draw new shapes every frame, which is not what I want.
If you look at the animation as it is now, this is how I want it to look, but I want to be able to control the number of boxes with a variable, and I want to be able to assign variables to some of the verticies in my Pshape called boxes.
I’ll put the code below. Any help, suggestions or input would be greatly appreciated.
thanks.
main code
import oscP5.*;
OscP5 oscP5;
float ramp1=450;
float ramp2=100;
float ramp3=1;
ArrayList<Polygon> polygons;
void setup() {
fullScreen(P3D);
// size(2700, 1500, P3D);
//background(0);
oscP5 = new OscP5(this, 12000);
PShape boxes = createShape(); //boxes is the name of my shape
boxes.beginShape();
boxes.strokeWeight(1);
boxes.stroke(0);
boxes.noFill();
//dimentions of base are 30X by 20 deep
// sides are 50 Y by 30 X
boxes.vertex(50, 50, 0); // this is the square top
boxes.vertex(20, 50, 0);
boxes.vertex(20, 50, -20);
boxes.vertex(50, 50, -20);
boxes.vertex(50, 50, 0);
boxes.vertex(70, 100, 0); //front rectangle
boxes.vertex(40, 100, 0);
boxes.vertex(20, 50, 0);
boxes.vertex(20, 50, -20); //back rectangle
boxes.vertex(40, 100, -20);
boxes.vertex(70, 100, -20);
boxes.vertex(50, 50, -20);
boxes.vertex(50, 50, -20); //close up bottom or middle square
boxes.vertex(70, 100, -20);
boxes.vertex(70, 100, 0);
boxes.vertex(70, 100, 0);
boxes.vertex(40, 100, 0);
boxes.vertex(40, 100, -20);
boxes.vertex(40, 100, -20); //bottom back rectangle
boxes.vertex(20, 150, -20);
boxes.vertex(50, 150, -20);
boxes.vertex(70, 100, -20);
boxes.vertex(70, 100, 0); //front bottom rectangle
boxes.vertex(50, 150, 0);
boxes.vertex(20, 150, 0);
boxes.vertex(40, 100, 0);
boxes.vertex(20, 150, 0); //bottom square
boxes.vertex(20, 150, -20);
boxes.vertex(50, 150, -20);
boxes.vertex(50, 150, 0);
boxes.endShape();
// Make an ArrayList
polygons = new ArrayList<Polygon>();
for (int i = 0; i < 200; i++) {
polygons.add(new Polygon(boxes));
}
}
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() {
background(255);
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);
// Display and move them all
for (Polygon poly : polygons) {
poly.display();
poly.move();
println(ramp1);
}
}
tab called Polygon
// A class to describe a Polygon (with a PShape)
class Polygon {
// The PShape object
PShape s;
// The location where we will draw the shape
float x, y, z;
// Variable for simple motion
float speed;
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;
}
}
// Draw the object
void display() {
pushMatrix();
//size(P3D);
fullScreen(P3D);
translate(x, y, z);
shape(s);
popMatrix();
}
}