/Users/petercappello/NetBeansProjects/56-2014/56-2014-1-Clique-OO/src/clique/Node.java |
package clique;
import java.awt.Color;
import java.awt.Graphics;
import static java.lang.Math.*;
@author
public class Node
{
public static final int IMAGE_SIZE = 600;
public static final int BORDER_SIZE = IMAGE_SIZE / 100;
public static final int FIGURE_SIZE = IMAGE_SIZE / 2;
private static int nNodes;
private static int CLIQUE_RADIUS;
private static int NODE_DIAMETER;
static void initialize( int nNodes )
{
Node.nNodes = nNodes;
NODE_DIAMETER = IMAGE_SIZE / nNodes;
Node.CLIQUE_RADIUS = ( IMAGE_SIZE - NODE_DIAMETER ) / 2 - BORDER_SIZE;
}
private final int nodeN;
private final double angle;
private final int x;
private final int y;
private final float redfraction;
Constructs a Node object whose number is nodeN.
@param nodeN
public Node( int nodeN )
{
this.nodeN = nodeN;
angle = 2.0 * PI * nodeN / nNodes;
x = FIGURE_SIZE + (int) ( CLIQUE_RADIUS * cos( angle ) ) ;
y = FIGURE_SIZE - ( (int) ( CLIQUE_RADIUS * sin( angle ) ) );
redfraction = (float) abs( cos( angle ) );
}
Draw this Node onto a Graphics object.
@param graphics
public void draw( Graphics graphics )
{
graphics.setColor( Color.red );
graphics.fillOval( x - NODE_DIAMETER / 2, y - NODE_DIAMETER / 2, NODE_DIAMETER, NODE_DIAMETER );
graphics.setColor( Color.black );
graphics.drawOval( x - NODE_DIAMETER / 2, y - NODE_DIAMETER / 2, NODE_DIAMETER, NODE_DIAMETER );
}
Draw an edge between this Node object & the argument Node object.
@param graphics
@param toNode
void drawEdge( Graphics graphics, Node toNode )
{
if ( nodeN > toNode.nodeN )
{
toNode.drawEdge( graphics, this );
return;
}
float blufraction = (float) abs( sin( toNode.angle ) );
graphics.setColor( new Color( redfraction, (float) 0.0, blufraction ) );
graphics.drawLine( x, y, toNode.x, toNode.y );
}
Draw an edge between this Node object & all higher-numbered nodes.
@param graphics
@param toNode
void drawEdges( Graphics graphics, Node[] nodes )
{
for ( int stopNode = nodeN + 1; stopNode < nNodes; stopNode++ )
{
drawEdge( graphics, nodes[ stopNode ] );
}
}
}