|
01 package grid;
02
03 import java.awt.geom.*;
04
05 import fang.Sprite;
06
07 /**Makes a grid shaped sprite.
08 * @author Jam Jenkins
09 */
10 public class Grid
11 extends Sprite
12 {
13 /**makes a sprite with a given number of
14 * rows and columns
15 * @param rows the number of vertical cells
16 * @param columns the number of horizontal cells
17 * @param margin the percent of the cell reserved
18 * for the line between cells
19 */
20 public Grid(int rows, int columns,
21 double margin)
22 {
23 Area area=new Area();
24 area.add(new Area(new Rectangle2D.Double(0, 0, 1, 1)));
25 double w=(1.0-margin)/columns;
26 double h=(1.0-margin)/rows;
27 for(int r=0; r<rows; r++)
28 {
29 for(int c=0; c<columns; c++)
30 {
31 double x=(c+0.5*margin)/columns;
32 double y=(r+0.5*margin)/rows;
33 Rectangle2D.Double cell=
34 new Rectangle2D.Double(x, y, w, h);
35 area.subtract(new Area(cell));
36 }
37 }
38 setShape(area);
39 }
40 }
|