MIC
Pat O'Sullivan
Department of Mathematics and Computer Studies
Mary Immaculate College, Limerick, Ireland

General Information

Student Resources and Information

Interests

Motion and Growth

To make a shape made with coordinates appear to move We first draw the basic shape.
For example, a yacht:

The procedure I used was:

to yacht

pu setxy 0 0 pd
setxy 0 20 setxy 50 20 setxy 50 30 ;back of the boat
setxy 0 30 setxy 50 150 setxy 100 30 setxy 50 30 ;the sail
setxy 50 20 setxy 130 20 setxy 100 0 setxy 0 0 ;front and bottom

end

To prepare the yacht for release from its moorings add a variable to each x-coordinate and name the procedure so that it requires an input. My version was:

to yacht :x

pu setxy 0 + :x 0 pd
setxy 0+:x 20 setxy 50+:x 20 setxy 50+:x 30 ;back of the boat
setxy 0+:x 30 setxy 50+:x 150 setxy 100+:x 30 setxy 50+:x 30 ;the sail
setxy 50+:x 20 setxy 130+:x 20 setxy 100+:x 0 setxy 0+:x 0 ;front and bottom

end


We can make the yacht sail from x = -100 to x = 100 as with the following:

to myacht

make "x -100
repeat 200 [yacht :x wait 1 clean make "x :x+1]
yacht :x ;this leaves us with a yacht on the screen after the last clean

end


You get this:

To create a shape which appears to "grow" we again create the basic shape suitably proportioned.
For example:

This was created by the procedures:

to flower

fd 70
lt 30 ;tilt the first triangle so that the stem doesn't go through a "petal"
repeat 5[triangle rt 72]
rt 30
bk 70

end
to triangle

repeat 3[fd 20 rt 120]

end


Now multiply each linear movement by a variable "scale factor" and rename the procedures so that they need an input as follows:

to flower :s

fd 70*:s
lt 30
repeat 5[triangle :s rt 72]
rt 30
bk 70*:s

end
to triangle :s

repeat 3[fd 20*:s rt 120]

end


This allows us to draw flowers of different sizes - scaled versions of the basic flower.
Examples:

We can make the flower "grow" as follows:

to gflower

make "s 0.1
repeat 20[flower :s wait 1 clean make "s :s+0.1]
flower :s ;leave a flower on the screen after the last clean

end
You get this (without the repetition):

You could combine growth and motion to produce a bubble effect:

I am using the library circle procedure here.
If you leave out the clean command in the bubble procedure you get the a nice "tube" effect:
 
Department Home
Home
The information found on personal pages should not be considered official material from Mary Immaculate College and the College does not accept any responsibility for its accuracy or otherwise.