Designing a program to draw this picture—a brick wall that you might later use as a stage background in some program you write—is good practice in analyzing structure.
While any good programming language might have many tools for drawing and moving, it wouldn't make sense to have special tools for drawing bricks because most programs don't involve bricks. That is the sort of tool you make yourself when you need it. When you need to draw bricks, having a special block lets your code use terms directly related to the problem you are trying to solve, rather than the more general-purpose terms that the computer uses for all kinds of tasks. The process of moving from what the programming language gives you to a natural language (one that humans speak to communicate) is a key part of good abstraction.
In this problem, you will build an abstraction for drawing a brick wall, first by creating , then blocks for drawing rows, and ultimately the goal:
.
A picture of a brick is rectangle, filled in "brick red" (darker than the primary-color red). There's no draw rectangle
block in snap. One way to fake it is by thinking of a rectangle as a very thick line.
These rounded ends are better for most line drawings, but not for this purpose.
You'd like the "top level" block to be something like this:
A human brick-layer would understand exactly how to build such a wall. A compute, doesn't know, so you must fill in the details. This means going from the abstract (draw a brick wall) to the concrete (pardon the pun). This involves problem decomposition.
There are two kinds of rows, so we make blocks that specialize in each:
Too much abstraction? It's possible to go overboard on abstraction and build so many blocks that your program is just as cluttered as it would be without the special blocks.
But it can also be useful to make a special block even when its definition is just one built-in block. For example, to draw the mortar (the cement between bricks, shown as white space), you can just use , but it might make sense to define a
draw mortar
block.
Why? You might later decide that 4 steps is the wrong thickness for mortar, and you'd rather have 5. Or you might want the mortar to be cement-colored, slightly gray. And your complete project might have blocks that aren't about mortar. With many
move
blocks scattered through your program, you would have to find and change each one, and keep putting in set pen color
blocks. With a draw mortar
block, you can just change its definition, and all the mortar in your picture will be changed.
The two kinds of rows should be exactly the same length. Your first try at drawing Row B may be a little too long. If so, think through what causes that bug.
How are you going to fix it? Should Row B have different-size bricks, different-size mortar gaps, or different-size half-bricks? If you're not sure, try all the possibilities and see which looks right in the finished wall. Or think "What would make most sense in a real brick wall?"
After you've drawn the picture at the top of this page, add more
inputs to the Draw a Brick Wall
block:
Add these one at a time, not all at once! When you modify the length of a brick, that should also change the length of a half-brick. When you modify the mortar thickness, that should also change the distance between rows (since that's mortar too).