forked from sweskills/prog-method-assignment-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pyramid.java
executable file
·38 lines (33 loc) · 1.17 KB
/
Pyramid.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* File: Pyramid.java
* Name:
* Section Leader:
* ------------------
* This file is the starter file for the Pyramid problem.
* It includes definitions of the constants that match the
* sample run in the assignment, but you should make sure
* that changing these values causes the generated display
* to change accordingly.
*/
import acm.graphics.*;
import acm.program.*;
import java.awt.*;
public class Pyramid extends GraphicsProgram {
private static final int brickWidth = 30;
private static final int brickHeight = 12;
private static final int brickInBase = 14;
public void run() {
putAllBricks();
}
private void putAllBricks(){
for( int row = 0; row < brickInBase; row++ ){
int bricksInRow = brickInBase - row;
for( int brickNumber = 0; brickNumber < bricksInRow; brickNumber++ ){
int x = ( getWidth()/2 ) - (brickWidth * bricksInRow) / 2 + brickNumber * brickWidth;
int y = getHeight() - brickHeight * (row+1);
GRect brick = new GRect( x , y , brickWidth , brickHeight );
add(brick);
}
}
}
}