I was wondering, in Processing, how to include an array as part of an object. Say I have an Object named "Node" and want it to contain a list of all the IDs of other nodes it's connected to. Please note that the length of this list can be variable. That is, one node can be connected to two or seven different other nodes. And how would I access that particular array within that object?
Here's some code I'm working with:
void setup(){
size(200,200);
Node node1 = new Node(color(255,0,0),40,80,2,0,.5,5,5,0);
int neighbor = 6;
node1.neighbors.add(neighbor);
}
void draw(){
}
class Node {
Set<Node> neighbors;
color c;
float xpos;
float ypos;
float xspeed;
float yspeed;
float damp;
float ForceX;
float ForceY;
int id;
// The Constructor is defined with arguments.
Node(color tempC, float tempXpos, float tempYpos, float tempXspeed, float tempYspeed, float tempDamp, float tempForceX, float tempForceY, int id_temp) {
c = tempC;
xpos = tempXpos;
ypos = tempYpos;
xspeed = tempXspeed;
yspeed = tempYspeed;
damp = tempDamp;
ForceX = tempForceX;
ForceY = tempForceY;
id = id_temp;
neighbors = new HashSet<Node>();
}
}
Thanks!