![]() |
The Computer Graphics Companion Online Edition Damian Scattergood 1999 |
|
RECURSIVE IMAGES (TURTLE GRAPHICS) |
|
Turtle Graphics is a system for drawing images that was first introduced in the Language LOGO. The basic premise for Turtle Graphics is quite simple. It is based on the idea of a turtle, which appears mid screen and can be moved by ordering it to move about by using a few basic directional commands. When the turtle moves it leaves a trail behind it, creating the displayed image. One of the features of Turtle graphics is that through recursive calls to functions quite stunning graphic images can be created. Your basic turtle can be moved forward by set distances and may be turned by a given angle. To experience the power of Turtle graphics you would require a full working version of LOGO, but the program below is simple enough to allow you to see how recursion works, and still creates some quite stunning results. |
![]() |
|
cx = 160; // Horizontal CenterX of screen. Pixel (cx, cy) //Plot first point at centre of screen angle = 0 //Initial angle at 0 degrees For a = 1 To repeats Simply changing some of the basic settings at the start of the program can change the basic image quite dramatically. The following are two examples of other images created by using alternate values. |
|
repeats = 100 forward = 2 incstep = 1 angle = 88 |
repeats = 55 forward = 1 incstep = 5 angle = 181 |
|
|
|
| The main advantage of this type of system is that it is extremely easy to
store a variety of images in quite a small amount of space. With the above examples it requires only four variables
to create each. So you can see that within any computer program it is possible to store a large number of graphic
images in a small space. This simple idea of recursion is found again in the area of fractal geometry, and can
be used in some very powerful ways. It is possible for instance to create quite complex patterns using only some
very simple algorithms. The algorithm above can be altered to create virtually an infinite numbers of patterns. To take the recursive program a bit further you can add color to your images and create more interesting results. Using color cycling on the images can create quite stunning effects. There are many different variations to this theme. Its really up to you and how much time you have to work and alter the basic algorithm. |