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

%CLR_BLACK = &H000000
%CLR_WHITE = &HFFFFFF
%CLR_RED = &H0000FF
%CLR_GREEN = &H00FF00
%CLR_BLUE = &HFF0000
%CLR_YELLOW = &H00FFFF
%CLR_CYAN = &HFFFF00
%CLR_MAGENTA = &HFF00FF
%CLR_SILVER = &HC0C0C0
%CLR_GRAY = &H808080
%CLR_MAROON = &H000080
%CLR_OLIVE = &H008080
%CLR_DARKGREEN = &H006400
%CLR_PURPLE = &H800080
%CLR_TEAL = &H808000
%CLR_NAVY = &H800000
%CLR_DARKRED = &H00008B
%CLR_INDIGO = &H4B0082
%CLR_ORANGE = &H00A5FF
%CLR_PINK = &HCBC0FF
%CLR_GOLD = &H00D7FF
%CLR_BROWN = &H2A2AA5
%CLR_CORAL = &H507FFF
%CLR_CRIMSON = &H3C14DC
%CLR_DARKORCHID = &HCC3299
%CLR_FORESTGREEN = &H228B22
%CLR_LAVENDER = &HFAE6E6
%CLR_LIME = &H00FF00
%CLR_SALMON = &H7280FA
%CLR_SEAGREEN = &H578B2E
%CLR_SKYBLUE = &HEBCE87
%CLR_TOMATO = &H4763FF
%CLR_VIOLET = &HEE82EE
%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 SHR 8) AND &HFF
END FUNCTION

FUNCTION GetBlue(c AS LONG) AS LONG
    FUNCTION = (c SHR 16) AND &HFF
END FUNCTION

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

FUNCTION BlendColors(c1 AS LONG, c2 AS LONG, ratio AS LONG) AS LONG
    LOCAL r1 AS LONG, g1 AS LONG, b1 AS LONG
    LOCAL r2 AS LONG, g2 AS LONG, b2 AS LONG
    LOCAL r AS LONG, g AS LONG, 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, lum AS LONG

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

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

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

    c = %CLR_SEAGREEN
    PRINT ""
    PRINT "  SeaGreen: hex "; HEX$(c, 6)
    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, 50%):"
    c = BlendColors(%CLR_RED, %CLR_BLUE, 50)
    PRINT "  Result: "; HEX$(c, 6)
    PRINT "  Red: "; GetRed(c); " Green: "; GetGreen(c); " Blue: "; GetBlue(c)

    PRINT ""
    PRINT "RGB test: RGB(128, 64, 192):"
    c = RGB(128, 64, 192)
    PRINT "  Hex: "; HEX$(c, 6)
    PRINT "  Components: R="; GetRed(c); " G="; GetGreen(c); " B="; GetBlue(c)

    FUNCTION = 0
END FUNCTION
