Three primitives allow to colour a figure. The primitive fill, fillzone and fillpolygon. .
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:
- The pen must be lowered (pd).
- 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:
Figure A.1 | At the beginning |
|
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.
Figure A.2 | With the primitive 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).
Figure A.3 | With the primitive fillzone, if you type: setpc 0 fillzone |
|
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
|
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.