RGB colours

David Bovill david at openpartnership.net
Wed Dec 19 10:52:48 EST 2007


These scripts should work anywhere without creating any objects - first time
use creates and custom property set as a two way array. Initialisation is
not fully tested - I think this works best as a library stack?

--> Colour | Conversion
-
function colour_NameToRgb colourName
    -- see also "colour_TranslateName"
    put the uOPN_ColourArray [colourName] of me into rgbColour
    if rgbColour is empty then
        colour_ConstructArray
        breakpoint
        return colour_NameToRgb(colourName)
    else
        return rgbColour
    end if
end colour_NameToRgb

function colour_RgbToName r, g, b
    if the paramcount = 1 then
        put item 2 of r into g
        put item 3 of r into b
        put item 1 of r into r
    end if

    put the uOPN_ColourArray [r,g,b] of me into colourName
    if colourName is empty then
        colour_ConstructArray
        breakpoint
        return colour_RgbToName(r, g, b)
    else
        return colourName
    end if
end colour_RgbToName

on colour_ConstructArray
    put the the colornames into colourNames
    put the backgroundcolor of me into oColour
    repeat for each line colourName in colourNames
        -- set the backgroundcolor of me to colourName
        -- put the backgroundcolor of me into rgbColour
        put colour_TranslateName(colourName) into rgbColour
        set the uOPN_ColourArray [rgbColour] of me to colourName
        set the uOPN_ColourArray [colourName] of me to rgbColour
    end repeat
    set the backgroundcolor of me to oColour
end colour_ConstructArray

function colour_TranslateName pColorName
    lock screen
    lock messages
    put the backcolor of me into oColorName
    put the backpixel of me into oBackPixel

    set the backcolor of me to pColorName
    get the effective backpixel of me
    set the backcolor of me to empty
    set the backpixel of me to it
    put the backcolor of me into tRGB

    -- set the backpixel of me to oBackPixel
    set the backcolor of me to oColorName

    return tRGB
end colour_TranslateName



More information about the use-livecode mailing list