Jump to content




question: how do i convert choosen letters, to be converted into a colour code?

help computer lua

  • You cannot reply to this topic
8 replies to this topic

#1 Goof

  • Members
  • 751 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

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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


#3 Goof

  • Members
  • 751 posts

Posted 21 January 2013 - 02:14 AM

okay.. i would try that asap :)

thanks

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 21 January 2013 - 05:42 AM

View PostTheOriginalBIT, on 21 January 2013 - 01:59 AM, said:

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.

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 January 2013 - 07:52 AM

View PostLyqyd, on 21 January 2013 - 05:42 AM, said:

View PostTheOriginalBIT, on 21 January 2013 - 01:59 AM, said:

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...

#6 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 21 January 2013 - 08:36 AM

If you don't know which hexadecimal matches which colour, I use this on CCemu xD

Posted Image

#7 Goof

  • Members
  • 751 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

#8 remiX

  • Members
  • 2,076 posts
  • LocationSouth 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)


#9 Goof

  • Members
  • 751 posts

Posted 24 January 2013 - 10:43 AM

Thanks :D i will try that.. ( sry for late post. )





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users