Brick Wall

TODO: Change blocks to:
draw brick wall, rows: () draw brick wall, rows: () bricks per row: () brick length: () brick width: () gap thickness: ()
Also change rowA and rowB to draw row A and draw row B (change images, text, starter file, solutions, and TG). --MF, 1/18/19

PG: The change, for me, is about clarifying and focusing on purpose. Why do I want to use abstraction to draw a brick wall? Why do I want to draw a brick wall? "In this lesson, you will…." Note that if we change U1 as suggested, students will already know how to use flat line ends to draw a brick, so we remind, not teach, there.

BH: What a great page! :-)

MF: need to address comments

Need to replace problem decomposition with modularity per AAP-3.B.2 and AAP-3.B.2. See vocab box on 3.2.4, Selecting Specific Data. (Appears on pages U2 furture OP Diagonal Design (mandala); 3.1.4, brick wall; 2.OP.4, plurals 1; and TG for 2.2 and 2.OP) --MF, 4/9/19
Humpty Dumpty on brick wall

In this project, you will use abstraction to draw a brick wall.

Sample image of brick wall

Drawing One Brick

A picture of a brick is just a rectangle with a brick red color. However, there's no draw rectangle block in snap. One way to draw one is by thinking of a rectangle as a very thick line. Here's the idea:

Any good programming language might have many tools for drawing and moving, but it wouldn't make sense to have special tools for drawing bricks because most programs don't involve bricks. That's the sort of tool you make yourself when you need it.
draw brick, length:(length) width:(width){set pen size to(width); move(length) steps}

    I'd like to swap the presentation here so students do what we want. First we should show the code and ask them what it does; then we should give them the starter file link and ask them to run the code. Otherwise, it's too tempting to run the code first, and then you never have the chance to figure out what it will do by reading it. --MF, 1/18/19
  1. Click here to load this file. Then save it to your Snap! account.
    It includes the complete draw brick block shown below. Read the code; then try it out.
    draw brick, length:(length#) width:(width#){set pen color to (red); set flat line ends to (true); set pen size to (width); pen down; move(length) steps; pen up}
  2. Ordinarily, Snap! draws rounded ends on thick lines: line with round ends. That's often the best choice, and you can see why below. But for bricks, we want flat line ends: flat line ends, and so we'll use set (flat line ends) to 'predicate input slot' to turn on flat line ends.

    Square with flat line ends versus square with round line ends
    flat vs. rounded line ends
    set [video capture] to 'predicate input slot' with menu open showing: turbo mode, flat line ends, video capture, mirror video
: Abstraction
AAP-3.B.1, AAP-3.B.5

As you learned in Unit 1 Lab 2 Page 2: Making Programs Talk, procedural abstraction is the process of developing a program by breaking up a large problem into smaller sub-problems.

Creating a draw brick block lets you think in terms of a procedure with a name related to the problem you are solving. This makes your code easier to read, and once you've coded and debugged the block, you don't need to think about how it works each time you use it. That's the beauty of procedural abstraction.

Using Problem Decomposition

You'd like the "top level" block to be something like this:
draw Brick Wall with (7) rows
Getting there involves problem decomposition: breaking the problem into smaller pieces.

There are two kinds of rows, so we make blocks that specialize in each:

    AAP-3.C
  1. Use draw brick to make blocks block rowA and block rowB.
  2. Read More 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 custom blocks. But it can be useful to make a custom block even when its definition is just one built-in block. For example, to draw the cement between blocks (shown as white space), you can just use Move 4 Steps, but it might make sense to define a draw cement block that uses move inside it.

    Why? You might later decide that four steps is the wrong thickness for cement and you'd rather have five. Or you might want the cement to be cement-colored, slightly gray. With many Move 4 Steps scattered through your program, you would have to find and change each one. To make matters worse, your complete project might have move blocks that aren't about cement. But with a draw cement block, you can change just its definition, and all the cement in your picture will be changed.

  3. The two kinds of rows should be exactly the same length. Your first try at drawing Row B is probably a little too long. If so, debug it.

    Debug by thinking about what you are trying to accomplish, not about your code. For example...

    • Should Row B have different-size bricks, different-size gaps, or just different-size bricks on the end?
    • If you're not sure, try all the possibilities and see which looks right in the finished wall.
    • Or think "What would make the most sense in a real brick wall?"
  4. Write and test the draw Brick Wall with (7) rows block.
    You might want to use the even? predicate from your U2L4-MathLibrary. You leaned about exporting and importing blocks on Unit 2 Lab 3 Page 1: What's a Predicate?
  5. Now Is a Good Time to Save

For the Create Task, you will need to be able to identify a procedural abstraction in a program you write and also clearly explain how your abstraction reduces the complexity of your code.

    AAP-3.B
  1. Talk with Another Pair How do you think procedural abstraction manages the complexity of a program?
  1. Add more inputs to draw Brick Wall (and as needed to row A and row B) for:
    1. Number of bricks per row
    2. length and width of a brick
    3. Gap thickness
    draw a Brick Wall with (8) Rows with Bricks per Row: (7) of Brick Length: (40) Width: (20) Gap Thickness: (5)
    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 row B end brick. When you modify the gap thickness, that should also change the distance between the rows.