The Real Value of the
It is, of course, much easier to create this script...
...than to create this one:
Even more importantly, using
repeat makes the structure of the program clearer. This is essential to good coding. Clearly structured code is easier to understand and easier to debug (to catch and fix errors). In the longer script above (without
repeat), we'd have to count the parts to see if it's right. And it would be very easy to make a mistake if we were drawing a 20-sided figure instead of a 4-sided one!
Analyze structure: Here are four pictures.
Which one(s) of these pictures could be drawn by running the following script?
- For each picture, write a script similar to the one above that describes how to draw it. (You don't need to say how long each side is (some) or how many degrees to turn (n), but you do need to show what code is repeated and how many times it repeats.)
- Experiment: Run yout scripts in snap and experiment with the number of degrees to make your pictures match the ones here. (Don't worry about matching the size exactly.)
Look for patterns.
Use to draw the following regular polygons using the smallest number of lines:
A regular polygon is a polygon in which all the sides are the same length and all the turning angles are the same. A square is a regular four-sided polygon.
- Equilateral Triangle
Repeat Block Self Check
Through how many degrees did your sprite turn altogether when you drew a pentagon?
No, consider the amount the sprite turned for all five of the rotations.
Which way did the sprite end up facing?
Correct! The sprite made a complete revolution.
No, How many times did the sprite turn?
What's the smallest number you can put into the blank numeric input of the
repeat block below to produce this picture?
Correct, the sprite must move and turn 9 times to draw the 9-pointed star.
Imagine (or draw) the sprite's movements step by step.
Imagine (or draw) the sprite's movements step by step all 10 times.
- Determine the turning angles to draw a 12-sided or 36-sided regular polygon.
Make small enough sides so that the shapes can fit on the stage. With more and more sides, the polygons get closer and closer to a circle. Is there a point at which the result is a circle?
- The code in self check question 2 above created a regular 9-pointed star. Through how many degrees did the sprite turn altogether to draw that star?
- Adjust the numbers in that script to get a regular 5-pointed star.
- Through how many degrees did your sprite turn altogether when you drew the five-pointed star?
- Find a starting direction so that the star sits "straight."