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, b | Colour |
---|---|
0, 0, 0 | Black |
0, 0, 255 | Blue |
255, 0, 0 | Green |
0, 255, 0 | Red |
255, 0, 255 | Magenta |
0, 255, 255 | Cyan |
255, 255, 0 | Yellow |
255, 255, 255 | White |
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 ifResult:
For more details see the Bitmap topic.