/** * Draw various tile patterns on a floor * @author Your Names Here * Quiz Section */ // The following libraries are needed for graphics and for colors import uwcse.graphics.*; import java.awt.Color; /** * Create a graphics window representing a tiled floor, and draw various tile * patterns on it */ public class Pattern{ // instance variables private int tileSize; // horizontal and vertical size of each tile in pixels private int height; // Height of the floor in pixels private int width; // Width of the floor in pixels private int rowcnt; // Number of rows of tiles on the floor private int colcnt; // Number of columns of tiles on the floor private GWindow floor; // Graphical Window for displaying the floor /** * Construct a new tile pattern window with the given number of rows and columns * and a default tile size. * @param rowcnt - number of rows on the floor * @param colcnt - number of cols on the floor */ public Pattern(int rows, int cols) { tileSize = 100; // default tile size rowcnt = rows; colcnt = cols; width = colcnt * tileSize; height = rowcnt * tileSize; floor = new GWindow(width, height); } /** * Return the tileSize for this floor * @return tileSize - Length of the side of the sqaure shaped tile */ public int getTileSize() { return tileSize; } /** * Return the Graphical Window on which the tiles will be drawn * @return floor - the Graphical window */ public GWindow getGWindow() { return floor; } /** Display Grid lines on the floor */ public void initializeFloor() { Line l; //display horizontal lines for(int i = 1; i <= rowcnt; i++) { int y = (i-1) * tileSize; l = new Line(0,y,width,y); l.addTo(floor); } //display vertical lines for(int j=1;j<=colcnt;j++) { int x =(j-1)*tileSize; l= new Line(x,0,x,height); l.addTo(floor); } } /** Add one tile to the top, left-hand corner of floor */ public void displayTopLeft(Tile t) { t.addTo(floor, 1, 1); } }