// file FillDemoShapes.java // Predrawn shapes to be filled. // by Harriet Fell // fell@ccs.neu.edu // July 2004 import java.awt.*; import java.awt.geom.*; import javax.swing.*; import java.awt.image.*; class FillDemoShapes { Graphics2D g2; int wd; int ht; FillDemoShapes(int shape, int[][] theGrid, int[][] pushNum) { // Initialize theGrid for (int i = 0; i < 20; i++) for (int j = 0; j < 20; j++) theGrid[i][j] = 0; // Initialize pushNum for (int i = 0; i < 20; i++) for (int j = 0; j < 20; j++) pushNum[i][j] = 0; switch (shape) { case 1 : aRectangle(theGrid); break; case 2 : BigU(theGrid); break; case 3 : RectandBars(theGrid); break; default : break; } } // the shapes void aRectangle(int[][] theGrid){ // rectangle for (int x = 5; x <= 15; x++){ theGrid[x][5] = 1; theGrid[x][15] = 1; theGrid[5][x] = 1; theGrid[15][x] = 1; } } void BigU(int[][] theGrid){ // [ on its side for (int x = 2; x <= 15; x++){ theGrid[x][2] = 1; theGrid[2][x] = 1; theGrid[15][x] = 1; if (x < 6 || x >11) { theGrid[x][15] = 1; } else { theGrid[x][6] = 1; } } for (int x = 6; x <= 15; x++){ theGrid[6][x] = 1; theGrid[11][x] = 1; } } void RectandBars(int[][] theGrid){ // large rectangle with interior lines for (int x = 0; x < 20; x++){ theGrid[0][x] = 1; theGrid[19][x] = 1; theGrid[x][0] = 1; theGrid[x][19] = 1; } for (int y = 3; y < 15; y++){ theGrid[3][y] = 1; theGrid[9][y] = 1; theGrid[15][y] = 1; } for (int y = 5; y < 17; y++){ theGrid[6][y] = 1; theGrid[12][y] = 1; } } /*void DrawShape(){ // draw your own shape short h, v; RGColor.black Color.black, EColor, c; Color.black.red = Color.black.green = Color.black.blue = 0; // black GetBackColor(&EColor); // white GetDot(g2, h,v); while (!(h < DrawMinX/size or h >= DrawMaxX/size or v < DrawMinY/size or v >= DrawMaxY/size)){ GetDotColor(h, v, c); if (SameColor(c, EColor)) Dot(g2, h, v, Color.black);// add to boundary else Dot(g2, h, v, EColor); // remove from GetDot(g2, h,v); } }*/ /* public void Dot(Graphics2D g2, int wd, int ht, int h, int v, Color c){ int size = Math.min(wd/20, ht/20); g2.setPaint(c); g2.fillOval(size*h + 1, size*v + 1, size - 1, size - 1); g2.setPaint(Color.black); } */ }