Let's create four procedures for the squares of sides 2 cm, 4 cm, 8 cm and 12 cm. We could store them in Proc 1, Proc 2, Proc 3 and Proc 4.
Here is one way of writing these procedures:
// Proc 1 - procedure for drawing 2 cm side square
Rpt 4 [
Fd 2
Rt
]
// Proc 2 - procedure for drawing 4 cm side square
Rpt 4 [
Fd 4
Rt
]
// Proc 3 - procedure for drawing 8 cm side square
Rpt 4 [
Fd 8
Rt
]
// Proc 4 - procedure for drawing 12 cm side square
Rpt 4 [
Fd 12
Rt
]
Next, we shall use the above procedures to draw the snails. Keep in mind that this is just a subset of the possible solutions. Both the procedures as well as the following programs can be written in multiple ways.
Proc 1
Rt
Fd 4
Lt
Proc 2
Rt
Fd 1
Lt
Proc 1
Here is one way of writing these procedures:
// Proc 1 - procedure for drawing 2 cm side square
Rpt 4 [
Fd 2
Rt
]
// Proc 2 - procedure for drawing 4 cm side square
Rpt 4 [
Fd 4
Rt
]
// Proc 3 - procedure for drawing 8 cm side square
Rpt 4 [
Fd 8
Rt
]
// Proc 4 - procedure for drawing 12 cm side square
Rpt 4 [
Fd 12
Rt
]
Next, we shall use the above procedures to draw the snails. Keep in mind that this is just a subset of the possible solutions. Both the procedures as well as the following programs can be written in multiple ways.
Program for the small snail as written from Main:
Proc 1
Rt
Fd 4
Lt
Proc 2
Rt
Fd 1
Lt
Proc 1
Program for the large snail as written from Main:
Proc 2
Rt
Fd 8
Lt
Proc 4
Rt
Fd 2
Lt
Proc 3
Rt
Fd 2
Lt
Proc 2
No comments:
Post a Comment