Transformations

You are going to use LOGO to perform the basic transformations of translation, rotation, reflection and enlargement.

You will then apply what you have learnt to produce basic computer animations and image distortion effects.


Translation.

1 Make a Shape

You need to have a shape to experiment with. This code will produce a pentagonal star.

repeat 5 [fd 200 rt 144]

2 Make the same shape any size.

It is more useful though to write this as a procedure called star which will draw a star of any size.

Open the procedure editor by typing:

edit "star

Then type or cut and paste this code in. Then save it by clicking on save and exit in the file menu.

to star :size
repeat 5 [fd :size rt 144]
end

Test the code by typing:

star 100

3 Translations.

There are lots of ways to translate the image. One of the easiest is to use the setxy command.
Try this set of commands. Note that cs clears the screen and ht hides the turtle.

cs star 100
setxy 0 200 star 100
setxy 200 200 star 100
setxy 200 0 star 100

4 Tidier Translations

You can get rid of the lines that join the stars by using the pu (pen up) and pd (pen down) commands. You can also use a repeat loop and the repcount command to automate the process.

cs repeat 4 [pu setxy repcount*50 repcount*50 pd star 50]

5 Simple Animation 1

The easiest way to make an animation is to draw the image in blue, leave it for a moment, draw over it in white to erase it and then redraw the image somewhere else. This procedure will draw a moving star. Open the procedure editor by typing edit "anim

to anim
repeat 200 [
setpc (list 0 0 255)
pu
setxy repcount repcount
pd
star 50
wait 2
setpc (list 255 255 255)
star 50 ]
end

Run the program with the command

anim

5 Simple Animation 2

This procedure uses the random command to draw a star which jumps around in a 500px square box. Open the procedure editor by typing edit "anim2

to anim2
repeat 200 [
setpc (list 0 0 255)
pu
setxy random 300 random 300
pd
star 50
wait 2
setpc (list 255 255 255)
star 50 ]
end

Run the program with the command

anim2

Enlargement

This program enlarges star each time it is drawn.

repeat 500 [cs star repcount]

Enlargement and Translation

This program enlarges and translates the star each time it is drawn.

repeat 200 [cs pu setxy repcount repcount pd star repcount]

Enlargement Rotation and Translation

This program enlarges rotates and translates the star each time it is drawn.

repeat 200 [cs pu setxy repcount repcount pd rt repcount*2 star repcount]


Last modified 1st February 2012