Re: convert hex colour to RGB values
Re: convert hex colour to RGB values
- Subject: Re: convert hex colour to RGB values
- From: Hamish Graham <email@hidden>
- Date: Tue, 20 Jul 2004 00:11:54 +0100
thanks for the reply, thats just what I'm looking for ;)
--h
On 19 Jul 2004, at 03:50, Graff wrote:
You could always use something like this:
----
set hexString to "123456789ABCDEF"
offset of "A" in hexString
--> 10
----
The "offset" command can be found in Standard Additions -> String
Commands -> offset:
offset: Find one piece of text inside another
offset
of Unicode text -- the source text to find the position of
in Unicode text -- the target text to search in
Result: integer -- the position of the source text in the
target, or 0 if not found
- Ken
On Jul 18, 2004, at 7:18 PM, Hamish Graham wrote:
Hi
I've written a little method to convert a hex string into RGB values,
however I feel there must be a better way to find the index number of
the hex, I have a second method ('getIndex()') to do it for me...
Is there a nice way to get the position of say "D" in a list like:
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C",
"D", "E", "F"}
below are my methods,
--
-- converts a hex string (e.g "#00CCFF") to RGB values in the range 0
-> 65535
--
on HexToRGB(hexValue)
set hexValue to text 2 through (count of hexValue) of hexValue --
strip the '#"
set RGBsmall to {0, 0, 0} -- range 0 -> 255, RGBsmall is here to
check the result more easily
set RGBbig to {0, 0, 0} -- range 0 -> 65535
repeat with k from 1 to count of hexValue by 2
set hex to text k through (k + 1) of hexValue
set numX to getIndex(first character of hex)
set numY to getIndex(second character of hex)
set dec to ((numX * (16 ^ 1) + numY * (16 ^ 0)))
set item ((k div 2) + 1) of RGBsmall to dec
set item ((k div 2) + 1) of RGBbig to ((dec + 1) * 256) - 1
end repeat
log RGBsmall
log RGBbig
return RGBbig
end HexToRGB
on getIndex(val)
set hexList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F"}
set indexNum to 0
repeat with s from 1 to count of hexList
if item s of hexList is equal to val then
set indexNum to s - 1
exit repeat
end if
end repeat
return indexNum
end getIndex
Thanks
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.