Arraylist Problem
in
Contributed Library Questions
•
1 year ago
Hello, I am fairly new to processing and I have a bit of a problem that I can't seem to work out. I have an several arraylists set up to hold my bubble image objects. I want to be able to define how many bubble objects each arraylist stores at one time so the screen doesn't become over crowded.
Any help would be greatly appreciated.
import hypermedia.video.*; // Imports the OpenCV library
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myBroadcastLocation;
OpenCV opencv; // Creates a new OpenCV object
PImage movementImg; // Creates a new PImage to hold the movement image
int poppedBubbles; // Creates a variable to hold the total number of popped bubbles
ArrayList bubbles; // Creates an ArrayList to hold the Bubble objects
ArrayList bubbles1;
ArrayList bubbles2;
ArrayList bubbles3;
ArrayList bubbles4;
ArrayList bubbles5;
ArrayList bubbles6;
PImage bubblePNG; // Creates a PImage that will hold the image of the bubble
PImage bubble1PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble2PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble3PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble4PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble5PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble6PNG; // Creates a PImage that will hold the image of the bubble
void setup()
{
size ( 640, 480 ); // Window size of 640 x 480
oscP5 = new OscP5(this,12000);
opencv = new OpenCV( this ); // Initialises the OpenCV library
opencv.capture( 640, 480 ); // Sets the capture size to 640 x 480
movementImg = new PImage( 640, 480 ); // Initialises the PImage that holds the movement image
poppedBubbles = 0;
bubbles = new ArrayList(); // Initialises the ArrayList
bubbles1 = new ArrayList();
bubbles2 = new ArrayList();
bubbles3 = new ArrayList();
bubbles4 = new ArrayList();
bubbles5 = new ArrayList();
bubbles6 = new ArrayList();
bubblePNG = loadImage("bubble.png"); // Load the bubble image into memory
bubble1PNG = loadImage("bubble1.png"); // Load the bubble image into memory
bubble2PNG = loadImage("bubble2.png"); // Load the bubble image into memory
bubble3PNG = loadImage("bubble3.png"); // Load the bubble image into memory
bubble4PNG = loadImage("bubble4.png"); // Load the bubble image into memory
bubble5PNG = loadImage("bubble5.png"); // Load the bubble image into memory
bubble6PNG = loadImage("bubble6.png"); // Load the bubble image into memory
myBroadcastLocation = new NetAddress("127.0.0.1",57120);
}
void draw()
{
bubbles.add(new Bubble( (int)random( 0, width - 40), -bubblePNG.height, bubblePNG.width, bubblePNG.height)); // Adds a new bubble to the array with a random x position
bubbles1.add(new Bubble1( (int)random( 0, width - 40), -bubble1PNG.height, bubble1PNG.width, bubble1PNG.height));
bubbles2.add(new Bubble2( (int)random( 0, width - 40), -bubble2PNG.height, bubble2PNG.width, bubble2PNG.height));
bubbles3.add(new Bubble3( (int)random( 0, width - 40), -bubble3PNG.height, bubble3PNG.width, bubble3PNG.height));
bubbles4.add(new Bubble4( (int)random( 0, width - 40), -bubble4PNG.height, bubble4PNG.width, bubble4PNG.height));
bubbles5.add(new Bubble5( (int)random( 0, width - 40), -bubble5PNG.height, bubble5PNG.width, bubble5PNG.height));
bubbles6.add(new Bubble6( (int)random( 0, width - 40), -bubble6PNG.height, bubble6PNG.width, bubble6PNG.height));
Any help would be greatly appreciated.
import hypermedia.video.*; // Imports the OpenCV library
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myBroadcastLocation;
OpenCV opencv; // Creates a new OpenCV object
PImage movementImg; // Creates a new PImage to hold the movement image
int poppedBubbles; // Creates a variable to hold the total number of popped bubbles
ArrayList bubbles; // Creates an ArrayList to hold the Bubble objects
ArrayList bubbles1;
ArrayList bubbles2;
ArrayList bubbles3;
ArrayList bubbles4;
ArrayList bubbles5;
ArrayList bubbles6;
PImage bubblePNG; // Creates a PImage that will hold the image of the bubble
PImage bubble1PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble2PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble3PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble4PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble5PNG; // Creates a PImage that will hold the image of the bubble
PImage bubble6PNG; // Creates a PImage that will hold the image of the bubble
void setup()
{
size ( 640, 480 ); // Window size of 640 x 480
oscP5 = new OscP5(this,12000);
opencv = new OpenCV( this ); // Initialises the OpenCV library
opencv.capture( 640, 480 ); // Sets the capture size to 640 x 480
movementImg = new PImage( 640, 480 ); // Initialises the PImage that holds the movement image
poppedBubbles = 0;
bubbles = new ArrayList(); // Initialises the ArrayList
bubbles1 = new ArrayList();
bubbles2 = new ArrayList();
bubbles3 = new ArrayList();
bubbles4 = new ArrayList();
bubbles5 = new ArrayList();
bubbles6 = new ArrayList();
bubblePNG = loadImage("bubble.png"); // Load the bubble image into memory
bubble1PNG = loadImage("bubble1.png"); // Load the bubble image into memory
bubble2PNG = loadImage("bubble2.png"); // Load the bubble image into memory
bubble3PNG = loadImage("bubble3.png"); // Load the bubble image into memory
bubble4PNG = loadImage("bubble4.png"); // Load the bubble image into memory
bubble5PNG = loadImage("bubble5.png"); // Load the bubble image into memory
bubble6PNG = loadImage("bubble6.png"); // Load the bubble image into memory
myBroadcastLocation = new NetAddress("127.0.0.1",57120);
}
void draw()
{
bubbles.add(new Bubble( (int)random( 0, width - 40), -bubblePNG.height, bubblePNG.width, bubblePNG.height)); // Adds a new bubble to the array with a random x position
bubbles1.add(new Bubble1( (int)random( 0, width - 40), -bubble1PNG.height, bubble1PNG.width, bubble1PNG.height));
bubbles2.add(new Bubble2( (int)random( 0, width - 40), -bubble2PNG.height, bubble2PNG.width, bubble2PNG.height));
bubbles3.add(new Bubble3( (int)random( 0, width - 40), -bubble3PNG.height, bubble3PNG.width, bubble3PNG.height));
bubbles4.add(new Bubble4( (int)random( 0, width - 40), -bubble4PNG.height, bubble4PNG.width, bubble4PNG.height));
bubbles5.add(new Bubble5( (int)random( 0, width - 40), -bubble5PNG.height, bubble5PNG.width, bubble5PNG.height));
bubbles6.add(new Bubble6( (int)random( 0, width - 40), -bubble6PNG.height, bubble6PNG.width, bubble6PNG.height));
1