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.
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.
Naming the Input: Choose a name for the input that makes its meaning clear to any reader: size
or side length
would be good. Type that name in the input field.
You have two choices about how to treat that new text:
draw square
to draw square picture
you'd click on "Title text" and type the word "picture.")
Your block header has changed: there is now a variable named size
(or whatever name you chose) after the title:
To use the size
variable in the draw square
script, drag the variable down into the move block. Whenever you need a new copy of a variable, just drag another down.
for
block.draw square
block in the scripting area now takes an input. Run this script with a few different inputs to check that it works: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.spell backwards
block that takes an input word or phrase and spells it backward. You may want your for
block to use draw polygon
block that takes two inputs:
sides
)length
)Be sure to test out your solution with several polygons with different lengths and numbers of sides.
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.nested polygons
with two or three levels of nesting and inputs that tell how many sides
and what side length
to use.