10.2 Second animation: The growing man

PIC

First, we’ll define a procedure man that draws the above schema. We use a variable to reproduce it at different scales

to man :c  
left 154 forward 44*:c back 44*:c  
left 52 forward 44*:c back 44*:c  
left 154 forward 40*:c  
left 154 forward 44*:c back :c*44  
left 52 forward 44*:c back :c*44  
left 154 forward 10*:c  
left 90 repeat 180[forward :c/2 right 2] right 90  
end

Now, we’ll create an animation that will make the man grow. To realize this, we’ll draw man 0.1, then man 0.2 man 0.3 ... until man 5. Between each man, we’ll erase the screen. We obtain two different procedures:

to man :c  
left 154 forward 44*:c back 44*:c  
left 52 forward 44*:c back 44*:c  
left 154 forward 40*:c  
left 154 forward 44*:c back :c*44  
left 52 forward 44*:c back :c*44  
left 154 forward 10*:c  
left 90 repeat 180[forward :c/2 right 2] right 90  
if :c=5[stop]  
cs ht man :c+0.1  
end  
 
to go  
cs ht  
man 0  
end

Finally to make the animation fluid, we’ll use animation mode and the primitive repaint.

to man :c  
left 154 forward 44*:c back 44*:c  
left 52 forward 44*:c back 44*:c  
left 154 forward 40*:c  
left 154 forward 44*:c back :c*44  
left 52 forward 44*:c back :c*44  
left 154 forward 10*:c  
left 90 repeat 180[forward :c/2 right 2] right 90  
repaint  
if :c=5[stop]  
cs ht man :c+0.1  
end  
 
to go  
cs ht animation  
man 0  
stopanimation  
end

Note: Here, the procedure man is recursive. In aother way, we could use the primitive for to make the variable :c from 0.1 to 5. Here is the program:

to man :c  
cs left 154 forward 44*:c back 44*:c  
left 52 forward 44*:c back 44*:c  
left 154 forward 40*:c  
left 154 forward 44*:c back :c*44  
left 52 forward 44*:c back :c*44  
left 154 forward 10*:c  
left 90 repeat 180[forward :c/2 right 2] right 90  
repaint  
end  
 
to go  
ht animation  
for [c 0 5 0.1][man :c]  
stopanimation  
end