Three primitives allow to colour a figure. The primitive fill, fillzone and fillpolygon. .

#### A.8.1 fill and fillzone

These primitives allow a shape to be coloured in. These primitives can be compared with the ’fill’ feature available in many image-retouching programs. This feature can extend to the margins of the design area. There are two rules that must be adhered to in order to use this primitive correctly:

1. The pen must be lowered (pd).
2. The turtle must not be located on a pixel of the colour with which the shape is to be filled. (If you want to colour things red, it can’t be sitting on red...)

Let’s take a look at an example to see the difference between fill and fillzone:

The pixel under the turtle is white right now. The primitive fill will colour all the neighbouring white pixels with the current pen colour. If for example, you type: setpc 1 fill.

Let’s now go back to the first case, if the pen colour of the turtle is black, the primitive fillzone colours all pixels until it encounters the current colour (here black).

This is a good example of the use of this primitive:

to halfcirc :c
# draw a half-circle of diameter :c
repeat 180 [fd  :c*tan 0.5 rt 1]
fd :c*tan 0.5
rt 90 fd :c
end

to tan :angle
# renders the tangent of the angle
output (sin :angle)/cos :angle
end

to rainbow :c
if :c<100 [stop]
halfcirc :c rt 180 fd 20 lt 90
rainbow :c-40
end

to dep
pu rt 90 fd 20 lt 90 pd
end

to arc
ht rainbow 400 pe lt 90 fd 20 bk 120 ppt pu rt 90 fd 20 pd
setpc 0 fill dep
setpc 1 fill dep
setpc 2 fill dep
setpc 3 fill dep
setpc 4 fill dep
setpc 5 fill dep
setpc 6 fill dep
end

#### A.8.2 Primitive fillpolygon

 fillpolygon list

It filled a shape using a series of triangles, so every time you drew a line the next triangle is filled. The list contains all instructions needed to draw the shape to fill.
• A first example to fill a square:
cs fillpolygon [ repeat 4 [forward 100 rt 90]]

 Step 1 Step 2 Step 3 Step 4
• A second example that draws a five pointed star:
repeat 5 [forward 100 fillpolygon [back 100 right 144 forward 100 ] back 100 left 72]

 Step 1 Step 2 Step 3 Step 4 Step 5