Code: Select all
' cairo_colortable.bas
' FreeBASIC Cairo example by lizard
' 256 colors with names
' based on the work of Roland Chastain
' source : wingraph.pas by Stefan Berinde
' http://math.ubbcluj.ro/~sberinde/wingraph/main.html#colornames
#include once "cairo/cairo.bi"
#define SetSourceColor(cairo, colour) cairo_set_source_rgb(cairo, _
(colour and &hFF0000) / &hFF0000, (colour and &h00FF00) / &h00FF00, (colour and &h0000FF) / &h0000FF)
dim as string names(255) = {"AliceBlue", "AlizarinCrimson","Amber","Amethyst","AntiqueWhite", _
"Aquamarine","Asparagus","Azure", "Beige", "Bisque", "Bistre", "BitterLemon", "Black", _
"BlanchedAlmond", "BlazeOrange", "Blue", "BlueViolet", "BondiBlue", "Brass", "BrightGreen", _
"BrightTurquoise", "BrightViolet", "Bronze", "Brown", "Buff", "Burgundy", "BurlyWood", _
"BurntOrange", "BurntSienna", "BurntUmber", "CadetBlue", "CamouflageGreen", "Cardinal", _
"Carmine", "Carrot", "Casper", "Celadon", "Cerise", "Cerulean", "CeruleanBlue", "Chartreuse", _
"Chocolate", "Cinnamon", "Cobalt", "Copper", "Coral", "Corn", "CornflowerBlue", "Cornsilk", _
"Cream", "Crimson", "Cyan", "DarkBlue", "DarkBrown", "DarkCerulean", "DarkChestnut", "DarkCoral", _
"DarkCyan", "DarkGoldenrod", "DarkGray", "DarkGreen", "DarkIndigo", "DarkKhaki", "DarkMagenta", _
"DarkOlive", "DarkOliveGreen", "DarkOrange", "DarkOrchid", "DarkPastelGreen", "DarkPink", "DarkRed", _
"DarkSalmon", "DarkScarlet", "DarkSeaGreen", "DarkSlateBlue", "DarkSlateGray", "DarkSpringGreen", _
"DarkTan", "DarkTangerine", "DarkTeaGreen", "DarkTerraCotta", "DarkTurquoise", "DarkViolet", _
"DeepPink", "DeepSkyBlue", "Denim", "DimGray", "DodgerBlue", "Emerald", "Eggplant", "FernGreen", _
"FireBrick", "Flax", "FloralWhite", "ForestGreen", "Fractal", "Fuchsia", "Gainsboro", "Gamboge", _
"GhostWhite", "Gold", "Goldenrod", "Gray", "GrayAsparagus", "GrayTeaGreen", "Green", "GreenYellow", _
"Heliotrope", "Honeydew", "HotPink", "IndianRed", "Indigo", "InternationalKleinBlue", _
"InternationalOrange", "Ivory", "Jade", "Khaki", "Lavender", "LavenderBlush", "LawnGreen", "Lemon", _
"LemonChiffon", "LightBlue", "LightBrown", "LightCoral", "LightCyan", "LightGoldenrodYellow", _
"LightGray", "LightGreen", "LightMagenta", "LightPink", "LightRed", "LightSalmon", "LightSeaGreen", _
"LightSkyBlue", "LightSlateGray", "LightSteelBlue", "LightYellow", "Lilac", "Lime", "LimeGreen", _
"Linen", "Magenta", "Malachite", "Maroon", "Mauve", "MediumAquamarine", "MediumBlue", "MediumOrchid", _
"MediumPurple", "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise", _
"MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose", "Moccasin", "MoneyGreen", "Monza", _
"MossGreen", "MountbattenPink", "Mustard", "NavajoWhite", "Navy", "Ochre", "OldGold", "OldLace", _
"Olive", "OliveDrab", "Orange", "OrangeRed", "Orchid", "PaleBrown", "PaleCarmine", "PaleChestnut", _
"PaleCornflowerBlue", "PaleGoldenrod", "PaleGreen", "PaleMagenta", "PaleMauve", "PalePink", _
"PaleSandyBrown", "PaleTurquoise", "PaleVioletRed", "PapayaWhip", "PastelGreen", "PastelPink", _
"Peach", "PeachOrange", "PeachPuff", "PeachYellow", "Pear", "Periwinkle", "PersianBlue", "Peru", _
"PineGreen", "Pink", "PinkOrange", "Plum", "PowderBlue", "PrussianBlue", "Puce", "Pumpkin", "Purple", _
"RawUmber", "Red", "Reef", "RobinEggBlue", "RosyBrown", "RoyalBlue", "Russet", "Rust", "SaddleBrown", _
"Saffron", "Salmon", "SandyBrown", "Sangria", "Sapphire", "Scarlet", "SchoolBusYellow", "SeaGreen", _
"SeaShell", "SelectiveYellow", "Sepia", "Sienna", "Silver", "SkyBlue", "SlateBlue", "SlateGray", _
"Snow", "SpringGreen", "SteelBlue", "SwampGreen", "Taupe", "Tangerine", "Teal", "TeaGreen", "Tenne", _
"TerraCotta", "Thistle", "Tomato", "Turquoise", "Ultramarine", "Vermilion", "Violet", "VioletEggplant", _
"Viridian", "Wheat", "White", "WhiteSmoke", "Wisteria", "Yellow", "YellowGreen", "Zinnwaldite"}
dim as long colors(255) = {&HF0F8FF, &HE32636, &HFFBF00, &H9966CC, &HFAEBD7, &H7FFFD4, _
&H7BA05B, &HF0FFFF, &HF5F5DC, &HFFE4C4, &H3D2B1F, &HCAE00D, &H000000, &HFFEBCD, &HFF9900, _
&H0000FF, &H8A2BE2, &H0095B6, &HB5A642, &H66FF00, &H08E8DE, &HCD00CD, &HCD7F32, &HA52A2A, _
&HF0DC82, &H900020, &HDEB887, &HCC5500, &HE97451, &H8A3324, &H5F9EA0, &H78866B, &HC41E3A, _
&H960018, &HED9121, &HADBED1, &HACE1AF, &HDE3163, &H007BA7, &H2A52BE, &H7FFF00, &HD2691E, _
&H7B3F00, &H0047AB, &HB87333, &HFF7F50, &HFBEC5D, &H6495ED, &HFFF8DC, &HFFFDD0, &HDC143C, _
&H00FFFF, &H00008B, &H654321, &H08457E, &H986960, &HCD5B45, &H008B8B, &HB8860B, &H545454, _
&H006400, &H310062, &HBDB76B, &H8B008B, &H556832, &H556B2F, &HFF8C00, &H9932CC, &H03C03C, _
&HE75480, &H8B0000, &HE9967A, &H560319, &H8FBC8F, &H483D8B, &H2F4F4F, &H177245, &H918151, _
&HFFA812, &HBADBAD, &HCC4E5C, &H00CED1, &H9400D3, &HFF1493, &H00BFFF, &H1560BD, &H696969, _
&H1E90FF, &H50C878, &H990066, &H4F7942, &HB22222, &HEEDC82, &HFFFAF0, &H228B22, &H808080, _
&HF400A1, &HDCDCDC, &HE49B0F, &HF8F8FF, &HFFD700, &HDAA520, &H7E7E7E, &H465945, &HCADABA, _
&H008000, &HADFF2F, &HDF73FF, &HF0FFF0, &HFF69B4, &HCD5C5C, &H4B0082, &H002FA7, &HFF4F00, _
&HFFFFF0, &H00A86B, &HF0E68C, &HE6E6FA, &HFFF0F5, &H7CFC00, &HFDE910, &HFFFACD, &HADD8E6, _
&HD2B48C, &HF08080, &HE0FFFF, &HFAFAD2, &HA8A8A8, &H90EE90, &HFF80FF, &HFFB6C1, &HFF8080, _
&HFFA07A, &H20B2AA, &H87CEFA, &H778899, &HB0C4DE, &HFFFFE0, &HC8A2C8, &H00FF00, &H32CD32, _
&HFAF0E6, &HFF00FF, &H0BDA51, &H800000, &HE0B0FF, &H66CDAA, &H0000CD, &HBA55D3, &H9370DB, _
&H3CB371, &H7B68EE, &H00FA9A, &H48D1CC, &HC71585, &H191970, &HF5FFFA, &HFFE4E1, &HFFE4B5, _
&HC0DCC0, &HC7031E, &HADDFAD, &H997A8D, &HFFDB58, &HFFDEAD, &H000080, &HCC7722, &HCFB53B, _
&HFDF5E6, &H808000, &H6B8E23, &HFFA500, &HFF4500, &HDA70D6, &H987654, &HAF4035, &HDDADAF, _
&HABCDEF, &HEEE8AA, &H98FB98, &HF984E5, &H996666, &HFADADD, &HDABDAB, &HAFEEEE, &HDB7093, _
&HFFEFD5, &H77DD77, &HFFD1DC, &HFFE5B4, &HFFCC99, &HFFDAB9, &HFADFAD, &HD1E231, &HCCCCFF, _
&H6600FF, &HCD853F, &H01796F, &HFFC0CB, &HFF9966, &HDDA0DD, &HB0E0E6, &H003153, &HCC8899, _
&HFF7518, &H800080, &H734A12, &HFF0000, &HC9FFA2, &H00CCCC, &HBC8F8F, &H4169E1, &H80461B, _
&HB7410E, &H8B4513, &HF4C430, &HFA8072, &HF4A460, &H92000A, &H082567, &HFF2400, &HFFD800, _
&H2E8B57, &HFFF5EE, &HFFBA00, &H704214, &HA0522D, &HC0C0C0, &H87CEEB, &H6A5ACD, &H708090, _
&HFFFAFA, &H00FF7F, &H4682B4, &HACB78E, &HBC987E, &HFFCC00, &H008080, &HD0F0C0, &HCD5700, _
&HE2725B, &HD8BFD8, &HFF6347, &H40E0D0, &H120A8F, &HFF4D00, &HEE82EE, &H991199, &H40826D, _
&HF5DEB3, &HFFFFFF, &HF5F5F5, &HC9A0DC, &HFFFF00, &H9ACD32, &HEBC2AF}
const screen_w = 1200
const screen_h = 716
screenres screen_w, screen_h, 32
windowtitle "Colortable"
' create a cairo drawing context, using the FB screen as surface
Dim As cairo_surface_t Ptr surface = cairo_image_surface_create_for_data(ScreenPtr(), _
CAIRO_FORMAT_ARGB32, screen_w, screen_h, screen_w * 4)
Dim As cairo_t Ptr canvas = cairo_create(surface)
dim as short i
screenlock
for x as short = 0 to 7
for y as short = 0 to 31
SetSourceColor(canvas,colors(i))
cairo_rectangle (canvas, x * 150 + 10, y * 22 + 10, 28, 12)
cairo_fill(canvas)
cairo_set_source_rgba(canvas, 1, 1, 1, 1) ' white
cairo_move_to(canvas, x * 150 + 44, y * 22 + 20)
cairo_show_text(canvas,names(i))
i += 1
next y
next x
screenunlock
' clean up the cairo context
cairo_destroy(canvas)
sleep
I must confess, the usage of such a table is limited. It may serve as reference. But with the source code it is possible to find another use for the tables.
Edit: Just seen, i have forgotten the screenlock/screenunlock here.