767 posts
Posted 21 January 2013 - 01:49 AM
Hello..
i am trying to make a table which has some letters/symbols, which i want, to be a colour code, and would not be displayed as the letter/symbol…
But.. i dont know how to actually start of, converting to a value, etc.. can anyone help me, or make a little tutorial, on how to convert single chars, to a variable/value. ?
btw: i have looked through the "paint" program, but i dont actually get where that part is.
Please help me:D
Thanks in Advance
7508 posts
Location
Australia
Posted 21 January 2013 - 01:59 AM
not sure if this can help any but…here is the hexlookup code that I use when trying to draw "paint" or "NPaintPro" images to the screen… as they are stored as hexadecimal ( 1-f )
local function hexLookup( char )
local value = tonumber(char, 16)
return (value and math.pow(2, value) or nil)
end
767 posts
Posted 21 January 2013 - 02:14 AM
okay.. i would try that asap :)/>
thanks
8543 posts
Posted 21 January 2013 - 05:42 AM
not sure if this can help any but…here is the hexlookup code that I use when trying to draw "paint" or "NPaintPro" images to the screen… as they are stored as hexadecimal ( 1-f )
local function hexLookup( char )
local value = tonumber(char, 16)
return (value and math.pow(2, value) or nil)
end
A minor correction; when storing the color values for conversion, one uses 0-f for the sixteen colors.
7508 posts
Location
Australia
Posted 21 January 2013 - 07:52 AM
not sure if this can help any but…here is the hexlookup code that I use when trying to draw "paint" or "NPaintPro" images to the screen… as they are stored as hexadecimal ( 1-f )
local function hexLookup( char )
local value = tonumber(char, 16)
return (value and math.pow(2, value) or nil)
end
A minor correction; when storing the color values for conversion, one uses 0-f for the sixteen colors.
And that is obviously what I meant… I was extremely tired when I posted that last night…
2088 posts
Location
South Africa
Posted 21 January 2013 - 08:36 AM
If you don't know which hexadecimal matches which colour, I use this on CCemu xD
767 posts
Posted 22 January 2013 - 09:25 AM
ehm… im actually lost…. :(/>
is this code, the right code, or the wrong code:
local function hexLookup( char )
local value = tonumber(char, 16)
return (value and math.pow(2, value) or nil)
end
and when i ran it, my code is this:
local match = {
" x HAHA"
}
local function hexLookup( char )
local value = tonumber(char, 16)
return (value and math.pow(2, value) or nil)
end
x = hexLookup("f")
term.setBackgroundColor(x)
write(" ")
term.clear()
is that the wrong way to print it.
can you give an example?
Please :D/>
2088 posts
Location
South Africa
Posted 22 January 2013 - 05:43 PM
It is working, but it's making the background
black and seeming that that is the default colour and you aren't noticing a difference.
Try this
local function hexLookup( char )
local value = tonumber(char, 16)
return (value and math.pow(2, value) or nil)
end
bG = {
' a bbbb a',
' a b b a',
' a b b a',
' a b b a',
' aaaaa bbbb aaaaa',
}
term.clear()
term.setCursorPos(1, 1)
for i = 1, #bG do
for z = 1, #bG[i] do
tmp = string.sub(bG[i], z, z)
if tmp == " " then
term.setBackgroundColour(colours.black)
write(' ')
else
term.setBackgroundColour(hexLookup(string.sub(bG[i], z, z)))
write(' ')
end
end
print()
end
term.setBackgroundColour(colours.black)
767 posts
Posted 24 January 2013 - 10:43 AM
Thanks :D/> i will try that.. ( sry for late post. )