Draw Shape

In the dialogue below, Alphie and Betty experiment by making a list of coordinates for a sprite to make this drawing:
sprite drawing letter A by going to each set of coordinates

 
Betty: Let's make a list of lists that have have x- and y-coordinates that can be used to draw the letter A.
Betty clicks "Make a variable", names it "A", and builds: set A to {{-50,20}, {-10,120}, {10,120}, {50,20}, {30,20}, {20,50}, {-20,50}, {-30,20}}
Alphie: So then we want to go through each of the eight lists and make the sprite go to (item 1, item 2) for each list. Let me try to build it.
Alphie makes script with for i=1 to 8 {glide 1 secs to x:(item 1 of item 1 of A) y:(item 2 of item 1 of A)} then glide to (0, 0)
Betty: So when i is 1, the sprite goes to "item 1 of item 1" and "item 2 of item 1". Then i is 2, so the sprite goes to "item 1 of item 2" and "item 2 of item 2". (Pauses.) Instead of using a for loop and counting from 1 to 8, what if we used the for each block? Here's how I would start it. I'm not sure what goes in the blanks after "x" and "y", though.
Betty makes script with for each (item) of (A) {glide 1 secs to x:(blank) y:(blank)} then glide to (0, 0)
Alphie: Hm... Good question. Also, this script isn't quite right. It doesn't connect the first and last points together. And I don't want the pen down as it goes from and to (0, 0).
Betty: It would also be nice if we could make this into a general script that draws any shape. Maybe we could make a block called draw shape (). Then we could also make a list of coordinates for letter B, C, or any other shape, and our block would draw them.
  1. Finish Betty's script using for each:
    script with for each (item) of (A) {glide 1 secs to x:(blank) y:(blank)} then glide to (0, 0)
 
Gamal has been looking over Betty's shoulder.
Gamal: I think you had trouble finishing that script because those item blocks get confusing. How about if you define a new data type called point that contains an X coordinate and a Y coordinate?
Gamal's idea is called data abstraction.
Gamal has built this block: point = list
Betty: Those blocks are trivial. They aren't going to make the rest of the program any shorter.
Gamal: They are going to make it easier to think about. Now, your list of points will obviously be a list of points:
letter A as list of points
Alphie: And we could make X coordinate and Y coordinate blocks so my drawing script would have things like x coord of item I of A instead of item 1 of item I of A, which was confusing.
Alphie's two other blocks: x coordinate = item 1 y coordinate = item 2
  1. Improve Betty's script using Gamal's idea, then make a green command block using that script: draw shape ()
    Notice that the input slot rectangle with two smaller orange rectangles inside shows that a list value is expected. This animation shows you how to specify the list input type:
    This animation needs to be redrawn with Plain Prototype Labels off!
    script with for each (item) of (A) {glide 1 secs to x:(blank) y:(blank)} then glide to (0, 0)
  2. Finish making the draw shape () block so that draw shape (A) produces the animation at the top of the page.
    I know this isn't about drawing a shape, but I didn't see a better place to put this... --MF
  1. Create a new data type called note beats to make your sound sequence lists easier to think about.
    Set Up Your Headphones or Speakers Play Sound Sequence
  2. Update the draw shape () block so that draw shape (A) completes a drawing of a letter A. (Choose the additional cordinates yourself.)
  3. Make a list of lists with coordinates to draw any other letter or shape. Check to see that draw shape () works with this new list.
  4. Notice the use of abstraction. Representing the message "HI" as list {A, B, C} hides all the complexity of the lists of coordinates used to draw the shapes.
  5. If you made other letters, write a block draw message () that takes a list of letters as input and uses draw shape () to draw a message.
    animation that shows drawing H then drawing I