From Bennu Wiki
Jump to navigation Jump to search


DWORD rgb ( <BYTE red> , <BYTE green> , <BYTE blue> , [<INT depth>] )


Finds the single color in the current color mode closest to the combined red, green, and blue values specified. In 32bit mode, the alpha is set to 255.

Equal to rgba(red,green,blue,255)


BYTE red - Level of red in the desired color from 0 to 255.
BYTE green - Level of green in the desired color from 0 to 255.
BYTE blue - Level of blue in the desired color from 0 to 255.
INT depth - Depth (optional paramter that may be omitted, only in 16 and 32 bit mode). When this parameter is used, the function returns the correct color code for the indicated depth.


DWORD : Returns the best matched color code.


Different color depths have different color codes, this is why rgb() is useful: it returns the appropriate code, based on the current color depth. When in 8bit mode, this code is 0..255 and when in 16bit mode 0..65535. In 32bit mode the code is 0xRRGGBBAA, two letters meaning one byte.

Using this function in different color depths can be tricky. This is because rgb() will return a different color code under different color depths. For example, when at 8bit, we do:

my_color = rgb(100,100,100);

my_color will most likely have the value 6 at this time. Suppose we change the color depth to 16bit now, using set_mode(). Now, my_color holds a totally different color than before, as 6 is nowhere near rgb(100,100,100) in 16bit mode. To counter this effect, my_color needs to be reinitialized:

my_color = rgb(100,100,100);

The same code, but rgb() now returns the proper code, as it always returns the code belonging to the current color depth. my_color will now be about 25388.


import "mod_map"
import "mod_text"
import "mod_key"
import "mod_wm"

Process Main()
    byte red=0;
    byte green=255;
    byte blue=0;
    set_text_color(rgb(red,green,blue)); // rgb finds the color closest to pure green and
                                         // passes it to set_text_color

    write(0,1,1,0,"Green text for everybody!"); //this text will be green


Used in example: set_text_color(), rgb(), write(), key(), exit_status

Functions Bdfload()Centerset()Colorfind()Colorsget()Colorsset()Fade()Fadeoff()Fadeon()Fntload()Fntnew()Fntsave()Fntunload()Fpgadd()Fpgdel()Fpgexists()Fpgload()Fpgnew()Fpgsave()Fpgunload()Getpixel()Glyphget()Glyphset()Graphicinfo()Graphicset()Mapblockcopy()Mapbuffer()Mapclear()Mapclone()Mapdel()Mapexists()Mapgetpixel()Mapinfo()Mapinfoget()Mapinfoset()Mapload()Mapname()Mapnew()Mapput()Mapputpixel()Mapsave()Mapsetname()Mapunload()Mapxput()Mapxputnp()Palclone()Paldel()Palget()Palload()Palmapassign()Palmapgetid()Palmapremove()Palnew()Palrefresh()Palsave()Palset()Palunload()Paletteconvert()Paletteroll()Pcxload()Pngload()Pngsave()Pointget()Pointset()Putpixel()Rgb()Rgbget()Rgba()Rgbaget()