Best way to convert color values

Bob Sneidar bobsneidar at iotecdigital.com
Thu Aug 8 12:01:32 EDT 2024


Yet another gem for my Validations library. I should probably separate out the conversion stuff as a conversions library. 

Bob S


> On Aug 7, 2024, at 11:14 AM, Richard Gaskin via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Paul Dupuis wrote:
> 
>> I can always write a routine to convert RGB to Hex and Hex to RGB, but
>> I am wondering if there is some clever trick in Livecode to do this.
>> 
>> For example: answer color -- returns RGB, but the htmlText of a line
>> wants <p bgcolor="#NNNNNN"> </p>
> 
> 
> If the target of the htmlText is a LiveCode field, I don't know of a method built into the LC engine, but it's easy enough to script:
> 
> function RGBtoHex pColor
>   repeat for each item tVal in pColor
>      get baseConvert(tVal, 10, 16)
>      if len(it) < 2 then put 0 before it
>      put it after tHex
>   end repeat
>   return "#"& tHex
> end RGBtoHex
> 
> 
> If the target of the htmlText is a browser widget, the browser engine's built-in "rgb" CSS function can do this:
> 
> <html>
>  <div style="background-color:rgb(130,30,230)"> Hello </div>
> </html>
> 
> --
> Richard Gaskin
> FourthWorld.com
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list