class ColorGrid
{
  private int[] grid;
  private int rows, cols;
  
  public static final int RED = -65536;
  public static final int GREEN = -16711936;
  public static final int BLUE = -16776961;
  public static final int CYAN = -16711681;
  public static final int MAGENTA = -65281;
  public static final int YELLOW = -256;
  public static final int WHITE = -1;
  
  // make a cols X rows ColorGrid that is randomly filled with colors
  ColorGrid(int rows, int cols)
  {
    grid = new int[cols*rows];
    this.cols = cols;
    this.rows = rows;
  }
  
  // randomly populate the grid using colors in the passed array
  public void populate(int[] colors)
  {
    for (int i = 0; i < grid.length; i++)
    {
      int ind = (int)( Math.random() * colors.length );
      grid[i] = colors[ind];
    }
  }
  
  public int get(int r, int c)
  {
    return grid[r*cols + c];
  }
  
  public void set(int r, int c, int col)
  {
    grid[r*cols + c] = col;
  }
  
  // returns a reference to the internal array
  // the flattened grid
  public int[] getGrid() { return grid; }
  
  public int rows() { return rows; }
  
  public int cols() { return cols; }
}
