I have a programming question about a problem that I have encountered multiple times regarding using variables specific to an object's instance, outside of the object.
What is the best way of extracting the location of multiple object instances, and then comparing them to determine factors such as their distance from one another?
I have written a very simple example to illustrate my question:
I have an array of objects. Each object simply consists of a circle of random size moving linearly across the screen. I would like to extract the x and y position from each instance of the object and then compare all of the object's locations. My objective is to display connections between ellipses that are close together, or perhaps not display the objects themselves, but only display ellipses when objects touch.
I appreciate that I may be thinking about this in the wrong way, so any help is much appreciated.
Thank you in advance.
Code:
Circle[] circles;
void setup() {
size(1000, 600);
background(255);
smooth();
circles = new Circle[1000];
for(int i = 0; i < circles.length; i++) {
circles[i] = new Circle(random(width), random(height), random(-1, 1), random(-1, 1), random(30));
I am having a problem when creating an arrayList full of arrays. At the moment each array is only two items long (it will be longer once the code is in place), and these arrays are added to an arrayList. We have used an arrayList instead of a normal 2D array because we don't know how many arrays will be generated by the program during setup.
When I print my arrayList, which is 3 items long, each item containing an array of 2 elements, I get the following message :
[[I@45c97b, [I@1aecc3a, [I@e22f2b]
Any ideas what is going on here? Is this some sort of storage location for the arrays on the system? How do I go about accessing the individual array items, inside of each arrayList item?
Hi all. Hoping somebody here can help me with a Processing problem.
I am adding elements to an arrayList when two strings are identical to one another using the code below.
for(int i = 0; i < postcodesArray.length; i++) {
for(int i2 = 0; i2 < allPostcodes.length; i2++) {
if(postcodesArray[i].equals(allPostcodes[i2])) {
N1.add(new Particle());
}
}
}
What I want however is multiple arrayLists, and each time the strings are identical, to extract the string at that point in the array, and use this string as an argument to the add method. So I would have say 3 arrayLists - N1, N2, N3 - and if the matching string was N3, it would add to the N3 arrayList and so forth. I hope this is clear. I plan to have 100 or so arrayLists, so using if statements to check each string seemed a bit too long of a solution.
I am stuck on a concept that in my head seems simple, but I just cannot get it to work. I am a bit of a newbie so please bear with me. Please could anybody help or point me in the direction of a tutorial that may help (I have looked). This is a simplified version, for ease of explanation, of what I want to do.
I want a function to trigger when a value goes above a certain threshold. Say an ellipse moving from top to bottom.
The problem I am having is that when this value then goes below the set threshold, the ellipse is removed from the screen.
What I want to happen, is every time the value goes above the threshold, a new instance of the ellipse is created, resulting in multiple ellipses moving down the screen, each one continuing on its own journey after being created.
I am trying to set up a very simple graphic EQ responding to incoming audio data from MaxMSP. However, I am having trouble with classes and any help would be very appreciated. This is the basic problem:
I have a set of public variables coming into Processing from MaxMSP, bin0, bin1, bin2, bin3 etc.
I have a Class, Bar, with different instances, bar0, bar1, bar2 etc.
I need each instance of Bar, to respond to its corresponding 'bin' value. For example, bar0 uses the bin0 data, bar1 uses the bin1 data and so forth...
My original idea was to state which variable to use when initialising the object. For example:
bar0 = new Bar(bin0);
bar1 = new Bar(bin1);
However this doesn't seem to work with a constantly changing value.
I may be thinking about this the wrong way so any help is much appreciated, thanks a lot.