/* * File: Pyramid.java * ------------------ * This program is a stub for the Pyramid problem, which draws * a brick pyramid. */ import acm.program.*; import acm.graphics.*; import java.awt.*; public class Pyramid extends GraphicsProgram { public void run() { for(int i= 1;i<=BRICKS_IN_BASE; i++){ for(int j= 1;j<=i;j++){ double dx = (getWidth()-i*BRICK_WIDTH)/2+(j-1)*BRICK_WIDTH; double dy = (getHeight()-(BRICKS_IN_BASE+1-i)*BRICK_HEIGHT); GRect rectangle = new GRect( dx, dy, BRICK_WIDTH, BRICK_HEIGHT); rectangle.setColor(Color.BLACK); add(rectangle); } } } private static final int BRICK_WIDTH = 30; private static final int BRICK_HEIGHT = 12; private static final int BRICKS_IN_BASE = 12; }