SetColor

Bitmaps
Aptilis 1

SetColor(BitmapHandle, ColourIndex, Red, Green, Value)

SetColor sets a color in a previously defined bitmap.
You can define up to 256 colours, and they range from 0 to 255.
You have to indicate a level a of red, a level of green and a level of blue.
Aptilis defines the colours for you when you create a bitmap. However, especially if you want to create pictures with a lot of close shades, you might not have all the colours you need in the default set, which is limited, and to be honest fairly poor in the blues.
By redefining colours however, you break the anti-aliasing scheme used by printAt.
Here is a reminder of how to mix colours:
r, v, bColour
0, 0, 0Black
0, 0, 255Blue
255, 0, 0Green
0, 255, 0Red
255, 0, 255Magenta
0, 255, 255Cyan
255, 255, 0Yellow
255, 255, 255White

For some, it might seem peculiar that, for example, green and red give yellow. This is because computer monitors (and TV screens) work according to additive synthesis, rather than the substractive variety, most commonly encountered with pigments and paper.
Just experiment, and you will soon be familiar with this 'weird' system. Here is the default Aptilis colour set. Index 0 is black, top left of the picture, 255 is white, bottom right.

Return Value:
0 if everything was OK, or -1 if you specified an incorrect index or an incorrect bitmap.

Example:

b = createBitmap(256, 256)


// We want a 256 gray palette
if b = -1
print("Ooops, could not create the bitmap....\n")
else

// Gray values
for i=0 to 255
setColor(b, i, i, i, i)
end for

i = 0
for y=0 to 15
gy = y * 16
for x = 0 to 15
gx = x * 16
box(b, gx, gy, gx + 16, gy + 16, i, 1)
i = i + 1
end for
end for

saveGIFFile("grays.gif", b)

end if
Result:

For more details see the Bitmap topic.