class Node { float x, y; float dx, dy; boolean fixed; String label; int count; void increment( ) { count++; } Node(String label) { this.label = label; x = random(width); y = random(height); } void relax( ) { 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; } } void update( ) { if (!fixed) { x += constrain(dx, -5, 5); y += constrain(dy, -5, 5); x = constrain(x, 0, width);// width*0.05, width*0.95); y = constrain(y, 0, height);//height*0.05, height*0.95); } dx /= 2; dy /= 2; } void draw( ) { //fill(nodeColor); noFill(); // stroke(0); // strokeWeight(0.5); // if(count > textWidth(label)) { //fill(colorMap(count), 128); ellipse(x, y, count, count); // fill(0); // textAlign(CENTER, CENTER); // text(label, x, y); // } // else { // ellipse(x, y, 6, 6); // } } color colorMap(int count) { return color(16*count, 128*count, 8*count, 255); } }