' Named Color Constants with RGB calculation
#COMPILE EXE
#DIM ALL

CONST CLR_BLACK = &H000000
CONST CLR_WHITE = &HFFFFFF
CONST CLR_RED = &H0000FF
CONST CLR_GREEN = &H00FF00
CONST CLR_BLUE = &HFF0000
CONST CLR_YELLOW = &H00FFFF
CONST CLR_CYAN = &HFFFF00
CONST CLR_MAGENTA = &HFF00FF
CONST CLR_SILVER = &HC0C0C0
CONST CLR_GRAY = &H808080
CONST CLR_MAROON = &H000080
CONST CLR_OLIVE = &H008080
CONST CLR_DARKGREEN = &H006400
CONST CLR_PURPLE = &H800080
CONST CLR_TEAL = &H808000
CONST CLR_NAVY = &H800000
CONST CLR_DARKRED = &H00008B
CONST CLR_INDIGO = &H4B0082
CONST CLR_ORANGE = &H00A5FF
CONST CLR_PINK = &HCBC0FF
CONST CLR_GOLD = &H00D7FF
CONST CLR_BROWN = &H2A2AA5
CONST CLR_CORAL = &H507FFF
CONST CLR_CRIMSON = &H3C14DC
CONST CLR_DARKORCHID = &HCC3299
CONST CLR_FORESTGREEN = &H228B22
CONST CLR_LAVENDER = &HFAE6E6
CONST CLR_LIME = &H00FF00
CONST CLR_SALMON = &H7280FA
CONST CLR_SEAGREEN = &H578B2E
CONST CLR_SKYBLUE = &HEBCE87
CONST CLR_TOMATO = &H4763FF
CONST CLR_VIOLET = &HEE82EE
CONST CLR_WHEAT = &HB3DEF5
FUNCTION RGB(r AS LONG, g AS LONG, b AS LONG) AS LONG
    FUNCTION = (b * 65536) OR (g * 256) OR r
END FUNCTION

FUNCTION GetRed(c AS LONG) AS LONG
    FUNCTION = c AND &HFF
END FUNCTION

FUNCTION GetGreen(c AS LONG) AS LONG
    FUNCTION = ((c \ 256)) AND &HFF
END FUNCTION

FUNCTION GetBlue(c AS LONG) AS LONG
    FUNCTION = ((c \ 65536)) AND &HFF
END FUNCTION

FUNCTION Luminance(BYVAL c AS LONG) AS LONG
    LOCAL r AS LONG
LOCAL g AS LONG
LOCAL b AS LONG
    r = GetRed(c)
    g = GetGreen(c)
    b = GetBlue(c)
    FUNCTION = (r * 30 + g * 59 + b * 11) / 100
END FUNCTION

FUNCTION BlendColors(BYVAL c1 AS LONG, BYVAL c2 AS LONG, BYVAL ratio AS LONG) AS LONG
    LOCAL r1 AS LONG
LOCAL g1 AS LONG
LOCAL b1 AS LONG
    LOCAL r2 AS LONG
LOCAL g2 AS LONG
LOCAL b2 AS LONG
    LOCAL r AS LONG
LOCAL g AS LONG
LOCAL b AS LONG
    r1 = GetRed(c1): g1 = GetGreen(c1): b1 = GetBlue(c1)
    r2 = GetRed(c2): g2 = GetGreen(c2): b2 = GetBlue(c2)
    r = (r1 * (100 - ratio) + r2 * ratio) / 100
    g = (g1 * (100 - ratio) + g2 * ratio) / 100
    b = (b1 * (100 - ratio) + b2 * ratio) / 100
    FUNCTION = RGB(r, g, b)
END FUNCTION

FUNCTION PBMAIN() AS LONG
    LOCAL c AS LONG
LOCAL lum AS LONG

    PRINT "Color Constants Demo"
    PRINT "===================="
    PRINT ""

    PRINT "Named colors (RGB hex values):"
    PRINT "  Black:   "; HEX$(CLR_BLACK)
    PRINT "  White:   "; HEX$(CLR_WHITE)
    PRINT "  Red:     "; HEX$(CLR_RED)
    PRINT "  Green:   "; HEX$(CLR_GREEN)
    PRINT "  Blue:    "; HEX$(CLR_BLUE)
    PRINT "  Yellow:  "; HEX$(CLR_YELLOW)
    PRINT "  Cyan:    "; HEX$(CLR_CYAN)
    PRINT "  Magenta: "; HEX$(CLR_MAGENTA)
    PRINT "  Orange:  "; HEX$(CLR_ORANGE)
    PRINT "  Purple:  "; HEX$(CLR_PURPLE)
    PRINT "  Gold:    "; HEX$(CLR_GOLD)
    PRINT "  Pink:    "; HEX$(CLR_PINK)

    PRINT ""
    PRINT "Color component extraction:"
    c = CLR_TOMATO
    PRINT "  Tomato: hex "; HEX$(c)
    PRINT "  Red:   "; GetRed(c)
    PRINT "  Green: "; GetGreen(c)
    PRINT "  Blue:  "; GetBlue(c)

    c = CLR_SEAGREEN
    PRINT ""
    PRINT "  SeaGreen: hex "; HEX$(c)
    PRINT "  Red:   "; GetRed(c)
    PRINT "  Green: "; GetGreen(c)
    PRINT "  Blue:  "; GetBlue(c)

    PRINT ""
    PRINT "Luminance values:"
    PRINT "  Black luminance: "; Luminance(CLR_BLACK)
    PRINT "  White luminance: "; Luminance(CLR_WHITE)
    PRINT "  Red luminance: "; Luminance(CLR_RED)
    PRINT "  Green luminance: "; Luminance(CLR_GREEN)
    PRINT "  Blue luminance: "; Luminance(CLR_BLUE)

    PRINT ""
    PRINT "Color blending (Red + Blue):"
    c = BlendColors(CLR_RED, CLR_BLUE, 50)
    PRINT "  Result: "; HEX$(c)
    PRINT "  Red: "; GetRed(c); " Green: "; GetGreen(c); " Blue: "; GetBlue(c)

    PRINT ""
    PRINT "RGB test:"
    c = 128 + 64 * 256 + 192 * 65536
    PRINT "  Hex: "; HEX$(c)
    PRINT "  Components: R="; GetRed(c); " G="; GetGreen(c); " B="; GetBlue(c)

    FUNCTION = 0
END FUNCTION
