final int N_PARTITIONS = 10;
int Diameter = 10;
int length = 101; // max number of nodes
float [] Node1 = new float [10];
float [] Node2 = new float [10];
void setup() {
background(255);
size(600,360);
}
void draw() {
background(255);
stroke(220,220,220);
for(int i=0; i<height; i=i+(height/N_PARTITIONS)){
line(0,i,width,i); // creates horizontal line for grid
}
for(int i=0; i <width; i=i+(width/N_PARTITIONS)){
line( i,0,i,height); // creates vertical lines for grid
}
stroke(0);
for (int i=0; i<Node1.length; i++)
{
fill (0);
ellipse(Node1[i], Node2[i], Diameter, Diameter); // array for nodes
}
for (int i=0; i<Node1.length-1; i++){
line (Node1[i],Node2[i],Node1[i+1],Node2[i+1]); // creates line connecting nodes
}
line (Node1[0],Node2[0],Node1[Node1.length-1],Node2[Node2.length-1]);
}
void mousePressed () { // creates node when mouse is pressed
Node2 = append(Node2, mouseY);
Node1 = append(Node1, mouseX);
}
1 Like
Some approaches:
- If the location of the node is not 0,0, draw the node.
- If the bit āmouseHasBeenPressedAtLeastOnceā is true, draw the node
- Populate the node with numbers outside the field of view (e.g. -1000,-1000), then update them to within the field of view after a mouse press.
- make an arraylist, rather than an array, and leave it empty at first. check if it is null before drawing.
There are many more ways, but any one of these approaches will work.
2 Likes