Lasso Soft Inc. > Home

[pk_rgbtohex]

Linkpk_rgbtohex
AuthorPier Kuipers
CategoryString
Version7.x
LicensePublic Domain
Posted10 Jan 2006
Updated16 Jan 2006
More by this author...

Description

Converts a comma delimited string holding RGB values into its Hex equivalent. Based on http://www.javascripter.net/faq/rgbtohex.htm

Sample Usage

Usage:
[pk_rgbtohex: ]

Example:
[pk_rgbtohex: '255, 24, 189'] -> '#FF18BD'
[pk_rgbtohex: '255, 24, 189', -nohash] -> 'FF18BD'

Source Code

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;

?>

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft