/* * ========================================================================== * GraphicsGrid.java: Definition and Management of the Graphics Grid.... * * Written By : Mark Austin October 2005 * ========================================================================== */ import java.lang.Math.*; import java.applet.*; import java.util.*; import java.io.*; import java.text.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; import java.awt.Color; import java.awt.font.*; import java.awt.image.*; import java.awt.geom.*; // Needed for affine transformation.... import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class GraphicsGrid { // Define fidelity for grid size.... private int gridSize = 50; private int xBorder = 40; private int yBorder = 40; private int smallDotSize = 3; // Constructor methods .... public GraphicsGrid() {} public void drawGrid( Graphics gs, int width, int height ) { // Setup Affine Transformation and 2D graphics context .... AffineTransform at = new AffineTransform(); at.translate( xBorder, height - yBorder ); at.scale( 1, -1); Graphics2D g2D = (Graphics2D) gs; g2D.setTransform (at); // Draw grid in pixel coordinates .... int iHorizontalDistance = width - 2*xBorder; int iVerticalDistance = height - 2*yBorder; Ellipse2D dot = new Ellipse2D.Double( 0, 0, (int) 5, (int) 5 ); for (int i = 0; i <= iHorizontalDistance; i = i + gridSize ) for (int j = 0; j <= iVerticalDistance; j = j + gridSize ) { // Adjust color for x- and y- axes .... if ( i == 0 || j == 0 ) g2D.setColor( Color.red ); else g2D.setColor( Color.blue ); // Draw grid dot .... g2D.translate( i, j ); g2D.scale( (double) 1.0, (double) -1.0 ); g2D.fill( dot ); g2D.scale( (double) 1.0, (double) -1.0 ); g2D.translate( -i,-j ); } } }