RGB to HEX

Alex Tweedly alex at tweedly.net
Fri Mar 3 03:24:39 EST 2006


Garrett Hylltun wrote:

> On Mar 2, 2006, at 10:28 AM, Jeanne A. E. DeVoto wrote:
>
>>  put "#" into theWebColor -- leading "#"
>>  repeat for each item myItem in theColorNumber -- numeric triplet -  
>> R,G,B
>>     get baseConvert(myItem,10,16)
>>     if the length of it is 1 then put zero before it  -- each  
>> component must be 2-digit
>>     put it after theWebColor
>>   end repeat
>>
>> -- 
>> jeanne a. e. devoto ~ revolution at jaedworks.com
>
>
> Thank you very much, this helped me figure out how to use that  
> baseConvert.  And thank you Sarah and FlexibleLearning for also  
> responding, very much appreciated.

baseConvert is a good, general purpose tool - but you can do this more 
concisely using format

 put "#" into theWebColor -- leading "#"
 repeat for each item myItem in theColorNumber -- numeric triplet -  R,G,B
    put format("%02X",myItem) after theWebColor
 end repeat

note - I prefer RGB colours to be #0A0B0F - i.e. upper case - so I used 
"%02X", but if you prefer lower case you can instead us "%02x"

-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.1.1/272 - Release Date: 01/03/2006




More information about the use-livecode mailing list