N
- Type of node to be stored in the particle viewer. This can be a Node
or any specialised subclass of it.E
- Type of edge to be stored in the particle viewer. This can be an Edge
or any specialised subclass of it.public class ParticleViewer<N extends Node,E extends Edge>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static float |
DAMPING
Default damping for all particle movements.
|
static float |
EDGE_STRENGTH
Default strength for all edges.
|
static float |
SPRING_STRENGTH
Default strength for all springs.
|
Constructor and Description |
---|
ParticleViewer(processing.core.PApplet parent,
int width,
int height)
Initialises the particle viewer.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addEdge(E edge)
Adds the given edge to those to be displayed in the viewer.
|
boolean |
addEdge(E edge,
float distance)
Adds the given edge to those to be displayed in the viewer.
|
boolean |
addForce(N node1,
N node2,
float force)
Creates a attractive or repulsive force between the two given nodes.
|
boolean |
addForce(N node1,
N node2,
float force,
float minDistance)
Creates a attractive or repulsive force between the two given nodes.
|
void |
addNode(N node)
Adds a node to those to be displayed in the viewer.
|
boolean |
addSpring(N node1,
N node2,
float length)
Creates a spring between the two given nodes.
|
boolean |
addSpring(N node1,
N node2,
float length,
float strength)
Creates a spring between the two given nodes with the given strength.
|
void |
draw()
Updates the particle view.
|
void |
dropSelected()
Releases the mouse-selected node so that it readjusts in response to other node positions.
|
N |
getNearest(float x,
float y)
Reports the node nearest to the given screen coordinates.
|
N |
getNearest(float x,
float y,
float radius)
Reports the node nearest to the given screen coordinates but within the given radius.
|
Particle |
getParticle(N node)
Provides the particle associated with the given node.
|
N |
getSelectedNode()
Reports the currently selected node of null if no nodes selected.
|
void |
resetView()
Resets the zoomed view to show the entire network.
|
void |
selectNearestWithMouse()
Allows a node to be selected with the mouse.
|
void |
setDrag(float drag)
Sets the drag on all particles in the system.
|
void |
spaceNodes()
Attempts to space out non-connected nodes from one another.
|
boolean |
tether(N node,
float strength)
Tethers the given node to its location with the given strength.
|
void |
updateParticles()
Updates the positions of nodes and edges in the viewer.
|
public static final float EDGE_STRENGTH
public static final float SPRING_STRENGTH
public static final float DAMPING
public ParticleViewer(processing.core.PApplet parent, int width, int height)
parent
- Parent sketch in which this viewer is to be drawn.width
- Width of the particle viewer in pixel units.height
- Height of the particle viewer in pixel units.public void draw()
public void updateParticles()
public void setDrag(float drag)
drag
- Drag effect (larger numbers slow down movement).public boolean addForce(N node1, N node2, float force)
node1
- First of the two nodes to have a force between them.node2
- Second of the two nodes to have a force between them.force
- Force to create between the two nodes. If positive, the nodes will attract
each other, if negative they will repulse. The larger the magnitude the stronger the force.public boolean addForce(N node1, N node2, float force, float minDistance)
node1
- First of the two nodes to have a force between them.node2
- Second of the two nodes to have a force between them.force
- Force to create between the two nodes. If positive, the nodes will attract
each other, if negative they will repulse. The larger the magnitude the stronger the force.minDistance
- Minimum distance within which no force is applied.public boolean addSpring(N node1, N node2, float length)
node1
- First of the two nodes to have a spring between them.node2
- Second of the two nodes to have a spring between them.length
- The length of this spring (natural rest distance at which the two nodes would sit).public boolean addSpring(N node1, N node2, float length, float strength)
node1
- First of the two nodes to have a spring between them.node2
- Second of the two nodes to have a spring between them.length
- The length of this spring (natural rest distance at which the two nodes would sit).strength
- The strength of this new spring.public boolean tether(N node, float strength)
node
- The node to be tethered.strength
- Strength of the tether.public Particle getParticle(N node)
node
- The node for which the associated particle is to be retrieved.public N getSelectedNode()
public N getNearest(float x, float y)
x
- x screen coordinate to queryy
- y screen coordinate to querypublic N getNearest(float x, float y, float radius)
x
- x screen coordinate to queryy
- y screen coordinate to queryradius
- Radius within which to search for nodes. If negative, all nodes are searched.public void addNode(N node)
node
- Node to add to the viewer.public boolean addEdge(E edge)
edge
- Edge to add to the display.public boolean addEdge(E edge, float distance)
edge
- Edge to add to the display.distance
- Distance of separation between the nodes.public void spaceNodes()
public void selectNearestWithMouse()
public void dropSelected()
public void resetView()