Brick Wall¶
By the end of this lab you'll be able to:
- Write a
brick()function and call it from nested loops - Apply the offset row pattern to stagger alternate rows
- Use
pencolorandfillcolorseparately to add outlines to filled shapes
Eight rows of warm red-brown bricks fill the canvas, each row staggered by half a brick — just like a real wall laid by a bricklayer.
Welcome to the Brick Wall!
Brick laying has a secret: alternate rows are shifted by half a brick so cracks don't line up
and the wall stays strong. You'll code that same pattern right now!
Let's code it together!
How the Wall Works¶
The brick(x, y, w, h, color) function draws one filled rectangle with a dark outline.
The offset pattern: if row % 2 == 1 (an odd row), shift the starting x by half a brick width.
This staggers the rows so each brick spans the joint of two bricks below it.
Sample Code¶
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 | |
What Do You Think Will Happen?
Odd rows (row % 2 == 1) are shifted right by bw // 2 = 35 pixels.
Will the bricks in row 1 (odd) line up with the joints in row 0, or with the middles of row 0's bricks?
Make your guess — then click Run to find out!
Try It Now¶
Row 1's bricks line up with the middles of row 0's bricks — that's what makes it a proper offset bond. Were you right?
How It Works¶
monty.fillcolor(color) and monty.pencolor('black') set the fill and outline colors independently. This is how you draw filled shapes with a visible border — monty.color(c) sets both to the same color, but fillcolor/pencolor let you separate them.
offset = bw // 2 if row % 2 == 1 else 0 is Python's ternary expression: a compact if/else on one line. It reads: "set offset to half a brick if the row is odd, otherwise zero."
Explanation Table¶
| Line | What it does |
|---|---|
monty.fillcolor(color) |
Set fill color separately from outline |
monty.pencolor('black') |
Set outline color to black |
offset = bw // 2 if row % 2 == 1 else 0 |
Ternary: offset odd rows by half a brick |
for side in [w, h, w, h] |
Draw four sides in one loop |
colors[(row + col) % 3] |
Cycle three brick shades across the wall |
Learning Check¶
Spot the Bug!
The program below draws a grid of bricks but they are NOT staggered — all rows line up!
Fix the one line that computes the offset so alternate rows shift by half a brick width.
Change offset = 0 to offset = bw // 2 if row % 2 == 1 else 0.
Experiments¶
-
Change brick colors. Replace
['firebrick','brown','darkred']with['lightyellow','beige','wheat']for a light stone wall. You'll know it worked when the wall color changes completely. -
Make taller bricks. Change
bh = 28tobh = 40. You'll know it worked when there are fewer rows of taller bricks. -
Try running-bond offset. Change the offset to
bw // 3for a different pattern called running bond. You'll know it worked when the stagger is one-third of a brick instead of one-half. -
Add mortar. Change
bh - 3tobh - 5andbw - 3tobw - 6. The larger gaps show more "mortar" between bricks. You'll know it worked when the dark gaps become wider.
Incredible Work!
You coded a brick wall complete with offset rows, separate fill and outline colors,
and a three-shade color cycle — that's real craft in Python!
Up next: Stars of Different Sizes — the geometry of a 5-pointed star.