We saw how to draw a square, and a rectangle with different sides. Now, we return to our house example p. 56 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.
In real size, the procedure square was:
to square repeat 4 [forward 150 right 90] end |
All the initial dimensions are multiplied by the scale. Hence, the procedure square becomes:
to square :c repeat 4 [forward 150*:c right 90] end |
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]
end
to tri :c
repeat 3[forward 150*:c right 120]
end
to porte :c
repeat 2[forward 70*:c right 90 forward 50*:c right 90]
end
to che :c
forward 55*:c right 90 forward 20*:c right 90 forward 20*:c
end
to dep1 :c
right 90 forward 50*:c left 90
end
to dep2 :c
left 90 forward 50*:c right 90 forward 150*:c right 30
end
to dep3 :c
penup right 60 forward 20*:c left 90 forward 35*:c pendown
end
to ma :c
carre :c dep1 :c porte :c dep2 :c tri :c dep3 :c che :c
end
|