This is a subset of solutions for the assignment Modular Programming with Squares. This is just one way of coding the solutions, there are multiple correct solutions for the same.
Rpt 4 [
Fd 12
Rt
]
2. The above square needs to be divided into two equal parts. You can do this with a horizontal or vertical line across the middle or divide the square along the diagonal. The solution below divides the cake along the horizontal line
across the middle.
Rpt 4 [
Fd 12
Rt
]
Fd 6
Rt
Fd 12
3. The square now needs to be divided into quarters. Two possible solutions, along the diagonals or using horizontal & vertical lines. The solution below divides the cake along the horizontal & vertical lines.
Rpt 4 [
Fd 12
Rt
]
Fd 6
Rt
Fd 12
Bk 6
Lt
Fd 6
Bk 12
Rpt 4 [
Fd 12
Rt
]
Rt 45
Fd 17
Lt 135
Fd 12
Lt 45
Bk 17
5. You need to divide the 12 x 12 cake into 9 equal pieces in this case. Each slice is going to be 4cm x 4 cm. Here is a solution using Nested Loops.
Rpt 4 [
Fd 12
Rt
]
Rpt 2 [
Rpt 2 [
Fd 4
Rt
Fd 12
Bk 12
Lt
]
Fd 4
Rt
]
Building Up with Squares as the Basic Building Blocks
1. The square can be drawn using the code:
Rpt 4 [
Fd 6
Rt
]
2. Here is the code for the rectangle drawn without using Nested Loops:
Rpt 4 [
Fd 6
Rt
]
Fd 6
Rpt 4 [
Fd 6
Rt
]
Fd 6
Rpt 4 [
Fd 6
Rt
]
3. As seen from the code above, there is a repeating pattern. After drawing each square, you need to move to the starting position for the next square. The above code can be rewritten using Nested Loops as:
Rpt 3 [
Rpt 4 [
Fd 6
Rt
]
Fd 6
]
4. & 5. To draw the large square that is double the size of the small square, different techniques can be employed. The easiest is to start from the midpoint of the figure. Each time, draw the small square and then turn 90 degrees to the right. Here is the code that uses Nested Loops.
Rpt 4 [
Rpt 4 [
Fd 6
Rt
]
Rt
]
Solutions to the Hopscotch figure:
Rpt 3 [ // Start drawing the rectangular part of the hopscotch from bottom left corner
Rpt 4 [
Fd 6
Rt
]
Fd 6
]
Rt // Here, you want to try and get to the midpoint of the large square
Fd 3 // 3 cm from the top of the rectangle to the midpoint of large square
Lt
Fd 6 // You have reached the midpoint of the large square now
Rpt 4 [ // Now draw the large square using the previously written code for the same
Rpt 4 [
Fd 6
Rt
]
Rt
]
No comments:
Post a Comment