Stars and spirals

In this lesson we will study how to draw all sorts of stars and spirals. Stars and spirals are normally created by drawing the same object multiple times while slightly changing the orientation and/or size of the object.

You can find all examples in this lesson here.

Stars

Let us start this lesson with a very simple star, consisting of a number of rays, emanating from the center of the screen. To draw one ray we simple draw a line. Next we must return to the center by moving backwards and we change the angle 6 degrees to draw the next ray. To go all around (360 degrees) we must repeat this 60 times, that is 2x3x10 times. To make the star large enough we first increase the size. This leads to the following program (STAR1.DRP):

We can easily extend this program to a nice little yellow sun against a blue sky. We first fill the screen with blue to create the sky and net set the color to yellow for the sun. We draw the rays as above but rotate 12 degrees (2x6) rather than 6 and repeat this only 30 times to go all around. Finally we draw a circle over it. This gives us the following program (SUN.DRP):

Now try to draw a moon rather than a sun. (Hint: fill the screen with black. Draw a yellow circle and a slightly overlapping black circle. You can also add some stars.)

To get a more complicated star we can use a well known technique: We draw a line, rotate over some (large) angle, and repeat this until we finally reach the starting position again. Here is an easy case: we repeatedly draw a line and rotate over 168 degrees (90+90-6-6). It is easy to see that we have to repeat this 15 times to get back to the starting position. Here is the program (STAR2.DRP). (The move at the start just takes case that the star appears in the middle of the picture.)

To obtain different stars, it is useful to use the advanced commands for changing the orientation and the number of repeats. The default form then becomes (STAR3.DRP):

Here we repeat 72 times an angle of 145 degrees. You can vary a lot with this. E.g. you can put different stars on top of each other, create stars of stars, change colors and line width, etc. Also you are not bounded to use lines. For example, here you have a star made from squares (STAR4.DRP):

Spirals

Let us now try to create some spirals. The main difference between stars and spirals is that in spirals we reduce (or enlarge) the drawing size after a number of steps. Here is a first very simple spiral: We simply draw a line, change the orientation, and reduce the size a bit. This we repeat a number of times (SPIRAL1.DRP):

You can easily vary on this theme by changing the amount we reduce the size, by changing the rotation angle, and by changing the number of repeats. Using the advance commands for these things we get the following global scheme (SPIRAL2.DRP):

The first size change is required because often we want to draw rather small lines to get a smooth impression. Rather than drawing lines we can also draw other shapes, e.g. circles (SPIRAL3.DRP):

One important problem with spirals is that afterwards it is difficult to tell what the current position, orientation, and size is. If we want to draw other things afterwards, we would like to restore these values. This can be done using the advanced commands to save and restore the environment. For example, here you find a simple program that draws two spirals next to each other. The first spiral consists of squares, the second of triangles. Before drawing the first spiral we save the environment (under any name) and before drawing the second spiral we restore the environment (using the same name) (SPIRAL4.DRP):

It is easy to vary on this theme in many different ways. Please don’t forget to mail your creations to markov@cs.ruu.nl.


Back to the Lessons Page