Ever wanted to transform Hex to RGB? Use this useful utility
on HexToRGB hex
---------------------------------------------------------------
-- Name:HexToRGB
-- Input:hex string
-- Description:Translate hex to rgb format
--
--
-- Output:rgb value
---------------------------------------------------------------
num1=0
num2=0
num3=0
str1=hex.char[2]&hex.char[1]
str2=hex.char[4]&hex.char[3]
str3=hex.char[6]&hex.char[5]
repeat with i=1 to 2
case (str1.char[i]) of
"A":num1=num1+power(i,4)*10
"B":num1=num1+power(i,4)*11
"C":num1=num1+power(i,4)*12
"D":num1=num1+power(i,4)*13
"E":num1=num1+power(i,4)*14
"F":num1=num1+power(i,4)*15
otherwise: num1=num1+power(i,4)*integer(str1.char[i])
end case
end repeat
repeat with i=1 to 2
case (str2.char[i]) of
"A":num2=num2+power(i,4)*10
"B":num2=num2+power(i,4)*11
"C":num2=num2+power(i,4)*12
"D":num2=num2+power(i,4)*13
"E":num2=num2+power(i,4)*14
"F":num2=num2+power(i,4)*15
otherwise: num=num+power(i,4)*integer(str2.char[i])
end case
end repeat
repeat with i=1 to 2
case (str3.char[i]) of
"A":num3=num3+power(i,4)*10
"B":num3=num3+power(i,4)*11
"C":num3=num3+power(i,4)*12
"D":num3=num3+power(i,4)*13
"E":num3=num3+power(i,4)*14
"F":num3=num3+power(i,4)*15
otherwise: num3=num3+power(i,4)*integer(str3.char[i])
end case
--i=i-1
end repeat
return (rgb(num1,num2,num3))
end
0 תגובות:
Post a Comment