class Node { float x, y; float dx, dy; boolean fixed; boolean relaxed; boolean updated; boolean drawn; String label; int count; void increment( ) { count++; } Node(String label) { this.label = label; x = random(width); y = random(height); relaxed=false; updated=false; drawn=false; } void relax( ) { if(!relaxed) { float ddx = 0; float ddy = 0; for (int j = 0; j < nodeCount; j++) { Node n = nodes[j]; if (n != this) { float vx = x - n.x; float vy = y - n.y; float lensq = vx * vx + vy * vy; if (lensq == 0) { ddx += random(1); ddy += random(1); } else if (lensq < 100*100) { ddx += vx / lensq; ddy += vy / lensq; } } } float dlen = mag(ddx, ddy) / 2; if (dlen > 0) { dx += ddx / dlen; dy += ddy / dlen; } relaxed=true; drawn=false; updated=false; } } void update( ) { if(relaxed && !updated) { if (!fixed) { x += constrain(dx, -5, 5); y += constrain(dy, -5, 5); x = constrain(x, width*0.03, width*0.97); //0, width);// y = constrain(y, height*0.01, height*0.99);//0, height);// } dx /= 2; dy /= 2; updated=true; } } // void draw( ) { // if (selection == this) { // fill(selectColor); // } // else if (fixed) { // fill(fixedColor); // } // else { // fill(nodeColor); // } // // stroke(0); // strokeWeight(0.5); // // rectMode(CORNER); // float w = textWidth(label) + 10; // float h = textAscent( ) + textDescent( ) + 4; // rect(x - w/2, y - h/2, w, h); // // fill(0); // textAlign(CENTER, CENTER); // text(label, x, y); // } // void draw( ) { // fill(nodeColor); // stroke(0); // strokeWeight(0.5); // ellipse(x, y, 6, 6); // } // void draw( ) { // if (fixed) { // fill(nodeColor); // stroke(0); // strokeWeight(0.5); // // rectMode(CORNER); // float w = textWidth(label) + 10; // float h = textAscent( ) + textDescent( ) + 4; // rect(x - w/2, y - h/2, w, h); // // fill(0); // textAlign(CENTER, CENTER); // text(label, x, y); // // } else { // fill(nodeColor); // stroke(0); // strokeWeight(0.5); // ellipse(x, y, 6, 6); // } // } void draw( ) { //fill(nodeColor); // noFill(); // stroke(0); // strokeWeight(0.5); // if(count > textWidth(label)) { // ellipse(x, y, count, count); if(!drawn) { fill(0); textAlign(CENTER, CENTER); text(label, x, y); drawn=true; relaxed=false; updated=false; } // } // else { // ellipse(x, y, 6, 6); // } } }