We saw how to draw a square, and a rectangle with different sides. Now, we return to our house example p. and
we’re going to modify the code to draw this house at any chosen scale.
The objective is to send an argument to the procedure house and according to this parameter, the house will be
smaller or bigger.
- house 1 will draw the house in real size.
- house 0.5 will draw the house at scale 0.5.
- house 2 will draw the house with double proportion.
In real size, the procedure square was:
repeat 4 [forward 150 right 90]
All the initial dimensions are multiplied by the scale. Hence, the procedure square becomes:
to square :c
repeat 4 [forward 150*:c right 90]
Therefore, when we’ll write square 2, the square will have for side length 150 × 2 = 300. Proportions are well
respected! In fact, we can see that we just need to modify all procedures replacing the length according to this rule:
fd 70 becomes fd 70*:c
fd 45 becomes fd 45*:c
to carre :c
repeat 4[forward 150*:c right 90]
to tri :c
repeat 3[forward 150*:c right 120]
to porte :c
repeat 2[forward 70*:c right 90 forward 50*:c right 90]
to che :c
forward 55*:c right 90 forward 20*:c right 90 forward 20*:c
to dep1 :c
right 90 forward 50*:c left 90
to dep2 :c
left 90 forward 50*:c right 90 forward 150*:c right 30
to dep3 :c
penup right 60 forward 20*:c left 90 forward 35*:c pendown
to ma :c
carre :c dep1 :c porte :c dep2 :c tri :c dep3 :c che :c