Advertisement
aazizyan

Untitled

Oct 25th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import acm.graphics.*;
  2. import acm.program.*;
  3.  
  4. public class Checkerboard extends GraphicsProgram {
  5.  
  6.     public void run() {
  7.         double sqSize = (double) getHeigth() / N_ROWS;
  8.  
  9.         for (int i = 0; i < N_ROWS; i++) {
  10.             for (int j = 0; j < N_ROWS; j++) {
  11.                 double x = j * sqSize;
  12.                 double y = i * sqSize;
  13.  
  14.                 drawGRect(x, y, sqSize);
  15.             }
  16.         }
  17.     }
  18.  
  19.     private void drawGRect(double x, double y, double sqSize) {
  20.         GRect sq = new GRect(x, y, sqSize, sqSize);
  21.         sq.setFilled((i + j) % 2 != 0);
  22.         add(sq);
  23.     }
  24.  
  25.  
  26. /* Private constants. */
  27.     private static final int N_ROWS = 8;
  28.     private static final int N_COLUMNS = 8;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement