Link | pk_rgbtohex |
Author | Pier Kuipers |
Category | String |
Version | 7.x |
License | Public Domain |
Posted | 10 Jan 2006 |
Updated | 16 Jan 2006 |
More by this author... |
Converts a comma delimited string holding RGB values into its Hex equivalent. Based on http://www.javascripter.net/faq/rgbtohex.htm
Usage: [pk_rgbtohex:] Example: [pk_rgbtohex: '255, 24, 189'] -> '#FF18BD' [pk_rgbtohex: '255, 24, 189', -nohash] -> 'FF18BD'
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
] Example: [pk_rgbtohex: '255, 24, 189'] -> '#FF18BD' [pk_rgbtohex: '255, 24, 189', -nohash] -> 'FF18BD' Based on http://www.javascripter.net/faq/rgbtohex.htm Written by Pier Kuipers, Dublin September 2004 pier@visualid.com http://www.pierkuipers.com/lasso.html ================================================================================ */ if: !(lasso_tagexists:'pk_rgbtohex'); define_tag:'pk_rgbtohex', -required='rgbString', -optional='nohash'; If:!(#rgbString -> (isa:'string')); local:'thisHex' = 'error'; Else; local:'rgbArray' = #rgbString -> Split:','; If:(#rgbArray -> size == 3); local:'thisHex' = string; local:'hexList' = (:'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); Iterate: #rgbArray, local:'thisN'; #thisN = (integer:#thisN); If:(#thisN == 0); #thisHex += '00'; Else; #thisN = (Math_Max: 0, #thisN); #thisN = (Math_Min: #thisN, 255); #thisN = (Math_Round: #thisN, 1); local:'thisN2' = (#thisN); #thisN = (((#thisN - (#thisN % 16)) / 16) + 1); #thisN2 = ((#thisN2 % 16) + 1); #thisHex += (#hexList -> get: #thisN); #thisHex += (#hexList -> get: #thisN2); /If; /Iterate; Else; local:'thisHex' = 'error'; /If; /If; If:!(local_defined:'nohash'); #thisHex = ('#' + #thisHex); /If; return: #thisHex; /define_tag; /If; ?>
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft