You are on page 1of 1

import acm.graphics.

*;
import acm.program.*;
import java.awt.*;

public class Pyramid extends GraphicsProgram {

/** Width of each brick in pixels */


private static final int BRICK_WIDTH = 30;

/** Width of each brick in pixels */


private static final int BRICK_HEIGHT = 12;

/** Number of bricks in the base of the pyramid */


private static final int BRICKS_IN_BASE = 14;

public void run() {


for (int j = 0; j < BRICKS_IN_BASE; j++) {
// To decrease the BRICKS_IN_BASE by 1 in each subsequent line,
draw the blocks j.
for (int i = 0; i < BRICKS_IN_BASE - j ; i++) {
GRect rect = new GRect (getWidth() / 2 - BRICKS_IN_BASE / 2 *
BRICK_WIDTH + BRICK_WIDTH/2*j + i*BRICK_WIDTH , getHeight()-BRICK_HEIGHT*j -
BRICK_HEIGHT, BRICK_WIDTH, BRICK_HEIGHT);
add(rect);
}
}
}
}

You might also like