Class ColorGrid

java.lang.Object
  extended by ColorGrid

public class ColorGrid
extends Object

Represents a color grid, a two-dimensional array of colors. Allows clients to set and modify the colors of individual cells and rectangular areas.


Constructor Summary
ColorGrid()
          Constructs a 100x100 grid, with all cells set to Color.WHITE.
ColorGrid(int rows, int columns)
          Constructs a rows x columns grid, with all cells set to Color.WHITE.
ColorGrid(int rows, int columns, Color startingColor)
          Constructs a rows x columns grid, with all cells set to startingColor.
 
Method Summary
 void brighten(int row, int column)
          Brightens (makes brighter) the color at the indicated row and column of the grid.
 void brighten(int row1, int column1, int row2, int column2)
          Brightens the indicated rectangle of the grid.
 int columns()
          Gets the number of columns.
 void darken(int row, int column)
          Darkens (makes darker) the color at the indicated row and column of the grid.
 void darken(int row1, int column1, int row2, int column2)
          Darkens the indicated rectangle of the grid.
 Color get(int row, int column)
          Gets the color at the indicated row and column of the grid.
 Color[][] grid()
          Gets a copy of the color grid as a 2-dimensional array.
 int rows()
          Gets the number of rows.
 void set(int row, int column, Color color)
          Sets the color at the indicated row and column of the grid.
 void set(int row1, int column1, int row2, int column2, Color color)
          Sets the color of the indicated rectangle of the grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColorGrid

public ColorGrid()
Constructs a 100x100 grid, with all cells set to Color.WHITE.


ColorGrid

public ColorGrid(int rows,
                 int columns)
Constructs a rows x columns grid, with all cells set to Color.WHITE.

Parameters:
rows - the number of rows.
columns - the number of columns.

ColorGrid

public ColorGrid(int rows,
                 int columns,
                 Color startingColor)
Constructs a rows x columns grid, with all cells set to startingColor.

Parameters:
rows - the number of rows.
columns - the number of columns.
startingColor - the starting color for all cells in the grid.
Method Detail

rows

public int rows()
Gets the number of rows.

Returns:
number of rows in the grid.

columns

public int columns()
Gets the number of columns.

Returns:
number of columns in the grid.

grid

public Color[][] grid()
Gets a copy of the color grid as a 2-dimensional array.

Returns:
a copy of the color grid.

get

public Color get(int row,
                 int column)
Gets the color at the indicated row and column of the grid.

Parameters:
row - the row of the grid cell to get - range 0 to rows-1 assumed.
column - the column of the grid cell to get. - 0 to columns-1 assumed.

set

public void set(int row,
                int column,
                Color color)
Sets the color at the indicated row and column of the grid.

Parameters:
row - the row of the grid cell to set - range 0 to rows-1 assumed.
column - the column of the grid cell to set - 0 to columns-1 assumed.
color - the color to which the grid cell is set.

set

public void set(int row1,
                int column1,
                int row2,
                int column2,
                Color color)
Sets the color of the indicated rectangle of the grid.

Parameters:
row1 - the first row of the rectangle - range 0 to rows-1 assumed.
column1 - the first column of the rectangle - range 0 to -1 assumed.
row2 - last row of the rectangle - range row1 to rows-1 assumed.
column2 - last column of the rectangle - range column1 to columns-1 assumed.
color - the color to which the grid cell is set.

darken

public void darken(int row,
                   int column)
Darkens (makes darker) the color at the indicated row and column of the grid.

Parameters:
row - the row of the grid cell to darken - range 0 to rows-1 assumed.
column - the column of the grid cell to darken - 0 to columns-1 assumed.

brighten

public void brighten(int row,
                     int column)
Brightens (makes brighter) the color at the indicated row and column of the grid.

Parameters:
row - the row of the grid cell to brighten - range 0 to rows-1 assumed.
column - the column of the grid cell to brighten - 0 to columns-1 assumed.

darken

public void darken(int row1,
                   int column1,
                   int row2,
                   int column2)
Darkens the indicated rectangle of the grid.

Parameters:
row1 - the first row of the rectangle - range 0 to rows-1 assumed.
column1 - the first column of the rectangle - range 0 to -1 assumed.
row2 - last row of the rectangle - range row1 to rows-1 assumed.
column2 - last column of the rectangle - range column1 to columns-1 assumed.

brighten

public void brighten(int row1,
                     int column1,
                     int row2,
                     int column2)
Brightens the indicated rectangle of the grid.

Parameters:
row1 - the first row of the rectangle - range 0 to rows-1 assumed.
column1 - the first column of the rectangle - range 0 to -1 assumed.
row2 - last row of the rectangle - range row1 to rows-1 assumed.
column2 - last column of the rectangle - range column1 to columns-1 assumed.