Adding an Input

You've seen many blocks that take inputs:
move 10 steps
turn clockwise 15 degrees
go to x:0 y:0
say Hello! for 2 secs
think Hmm... for 2 secs
play note 60 for 0.5 beats

Your draw square block draws squares of only one particular size—the size built into its script. You can improve your block to draw squares of any size by giving your block an input.

  1. Edit your draw square block to give it an input. To edit a block, right-click on it (or control-click or two-finger-click) and select "edit." Use the video to get the idea. You can read the detailed instructions (in yellow below) to learn more about what you are doing.
    This is the first time we've hinted that they might be using a touchscreen/touchpad. We should maybe be consistent about this? Define "secondary click" carefully once and then just use it? PG: This is getting overwhelmingly complicated and just begs to be obsolete when the next technology comes in. Right-click, control-click, two-finger-click....
    adding input to block
Is it kosher for one TIF to assume that you did an earlier TIF? --PG? That's what the links are for. :) MF
 
  1. If you made the house block on the previous page, edit your triangle and house blocks so that you can draw houses of any size you specify as input.
  2. Create a spell backwards block that takes an input word or phrase and spells it backward. You may want your for block to use length of in order to know when to stop spelling.
  3. draw polygon () sides of length ()
    You may wish to look back at the work with polygons you did in Lab 3. How many degrees altogether? How many turns?
  4. Create a draw polygon block that takes two inputs:
    • a number of sides (call the variable sides)
    • the length of each side (call the variable length)

    Be sure to test out your solution with several polygons with different lengths and numbers of sides.

    This draw polygon block generalizes the pattern of draw square, draw triangle, draw hexagon, and so on. It does so by adding an input that expresses the difference from one block to another, namely, the number of sides. Adding an input to generalize a pattern is going to be a very important technique later in the course. This is an important example of abstraction, one of the central ideas of this course and of computer science in general.
  5. You may wish to review how you nested squares in squares. Create a new procedure called nested polygons with two or three levels of nesting and inputs that tell how many sides and what side length to use.