Best way to convert color values
Richard Gaskin
ambassador at fourthworld.com
Wed Aug 7 14:14:08 EDT 2024
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
More information about the use-livecode
mailing list