next up previous contents index
Next: Let's get practical! Up: Program examples Previous: All about colours   Contents   Index

Introduction

Fist, a few explanations: you will note that the command setpc can take either a list or a number as a parameter. Here, we are interested in coding RGB values.
Every colour in XLOGO is coded using three values: red, green and blue, whence the name RGB encoding. The three numbers in the list parameter to the primitive setpc therefore represent respectively the red, blue and green components of a colour. This encoding is not really intuitive, and you can get an idea of the colour which will be given by the encoding by using the dialogue box Options--> Choose the pen colour.
Using this encoding, it is very easy to transform an image. For example, if you want to turn a colour photo into a greyscale image, you can change the colour of each pixel of the image to the average value of the three components [r g b]. Imagine that the colour of one dot of the image is given by the encoding [0 100 80]. You calculate the average of these three numbers: $ \frac{0+100+80}{3}=60$, and then assign the colour [60 60 60] to this pixel. This operation has to be carried out on each pixel of the image.


next up previous contents index
Next: Let's get practical! Up: Program examples Previous: All about colours   Contents   Index
Loïc 2008-06-08