• Print

Author Topic: color to RGB  (Read 86 times)

Gorlock

  • Sr. Member
  • ****
  • Posts: 337
    • Email
color to RGB
« on: December 15, 2012, 02:52:04 PM »
I wrote this for one of my programs that needs to be in 32 bit color:

Code: [Select]
FUNCTION colortorgb& (c)
SELECT CASE c
    CASE 0
        r = 0
        g = 0
        b = 0
    CASE 1
        r = 0
        g = 0
        b = 168
    CASE 2
        r = 0
        g = 168
        b = 0
    CASE 3
        r = 0
        g = 168
        b = 168
    CASE 4
        r = 168
        g = 0
        b = 0
    CASE 5
        r = 168
        g = 0
        b = 168
    CASE 6
        r = 168
        g = 84
        b = 0
    CASE 7
        r = 168
        g = 168
        b = 168
    CASE 8
        r = 84
        g = 84
        b = 84
    CASE 9
        r = 84
        g = 84
        b = 252
    CASE 10
        r = 84
        g = 252
        b = 84
    CASE 11
        r = 84
        g = 252
        b = 252
    CASE 12
        r = 252
        g = 84
        b = 84
    CASE 13
        r = 252
        g = 84
        b = 252
    CASE 14
        r = 252
        g = 252
        b = 84
    CASE 15
        r = 252
        g = 252
        b = 252
END SELECT
colortorgb& = _RGB32(r, g, b)
END FUNCTION

There must be an easier/shorter way, I thought there was a command where you could just switch between them but I might be mistaken.

TerryRitchie

  • Hero Member
  • *****
  • Posts: 2264
  • FORMAT C:\ /Q /U /AUTOTEST (How to repair Win8)
    • Email
Re: color to RGB
« Reply #1 on: December 15, 2012, 03:22:15 PM »
Putting them into arrays may be easier for you.

Code: [Select]
CONST cRED = 0, cGREEN = 1, cBLUE = 2
CONST BLACK = 0, BLUE = 1, GREEN = 2, CYAN = 3, RED = 4
CONST PURPLE = 5, BROWN = 6, GRAY = 7, LIGHTGRAY = 8, LIGHTBLUE = 9
CONST LIGHTGREEN = 10, LIGHTCYAN = 11, LIGHTRED = 12, MAGENTA = 13
CONST YELLOW = 14, WHITE = 15

DIM RGB(15, 2)

RGB(BLACK, cRED) = 0
RGB(BLACK, cGREEN) = 0
RGB(BLACK, cBLUE) = 0

RGB(BLUE, cRED) = 0
RGB(BLUE, cGREEN) = 0
RGB(BLUE, cBLUE) = 168

RGB(GREEN, cRED) = 0
RGB(GREEN, cGREEN) = 168
RGB(GREEN, cBLUE) = 0

etc..

mycolor& = colortorgb&(MAGENTA)
mycolor& = colortorgb&(13) '           same as asking for MAGENTA

FUNCTION colortorgb& (c)
    colortorgb& = _RGB32(RGB(c, 0), RGB(c, 1), RGB(c, 2))
END FUNCTION

  • Print