/** * Add Spring Layout capabilities to a node. * Basically, it add a charge (electrical) to a node, stores a force * that applies to this node and a velocity (for animation). */ class SpringNode extends Node { PVector force = new PVector(); PVector velocity = new PVector(); float charge; SpringNode(float x, float y, float charge){ super(x, y); this.charge = charge; } SpringNode(PVector position, float charge){ super(position); this.charge = charge; } void setCharge(float charge){ this.charge = charge; } float getCharge(){ return this.charge; } void setForce(PVector force){ this.force = force; } PVector getForce(){ return this.force; } void applyForce(PVector force){ this.force.add(force); } /** * Adds a alpha blended visualization of the charge. */ void draw(){ super.draw(); if (graph.isSelected(this)){ fill(#E5F05C, 50); } else { fill(#5CD3F0, 50); } ellipse(position.x, position.y, defaultSize*charge, defaultSize*charge); } }